floraison / et-orbi

Time zones for fugit and rufus-scheduler. Urbi et Orbi.
MIT License
24 stars 11 forks source link

Timezone ignored in cron.match? #21

Closed assembler closed 5 years ago

assembler commented 5 years ago

Timezone seems to be completely irrelevant when calling match? on cron object:

> cron = Fugit::Cron.parse("0 0 * * * PST8PDT")
=> #<Fugit::Cron:0x00007ff5e1422e60 @original="0 0 * * * PST8PDT", @cron_s=nil, @seconds=[0], @minutes=[0], @hours=[0], @monthdays=nil, @months=nil, @weekdays=nil, @zone="PST8PDT", @timezone=#<TZInfo::DataTimezone: PST8PDT>>

> cron.match?(Time.utc(2019, 1, 1, 0, 0, 0))
=> true

> cron.match?(Time.new(2019, 1, 1, 0, 0, 0, TZInfo::Timezone.get('UTC')))
=> true

> cron.match?(Time.new(2019, 1, 1, 0, 0, 0, TZInfo::Timezone.get('CET')))
=> true

> cron.match?(Time.new(2019, 1, 1, 0, 0, 0, TZInfo::Timezone.get('PST8PDT')))
=> true

I thought setting timezone in cron would make it only match in specific time zone. In example above i'd expect it to match only in PST8PDT midnight.

jmettraux commented 5 years ago

Sorry, what version of Ruby on what Operating System are you using?

On my ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-darwin17]

Time.new(2019, 1, 1, 0, 0, 0, TZInfo::Timezone.get('UTC'))
  # ==> TypeError: can't convert TZInfo::DataTimezone into an exact number
assembler commented 5 years ago

its ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]

jmettraux commented 5 years ago

OK, I'll look into this (from the Ruby < 2.6 point of view for now)

require 'fugit'

cron = Fugit::Cron.parse("0 0 * * * PST8PDT")
p cron
  # => #<Fugit::Cron:0x00007fb3b8bdf880
  #      @original="0 0 * * * PST8PDT", @cron_s=nil, @seconds=[0],
  #      @minutes=[0], @hours=[0], @monthdays=nil, @months=nil, @weekdays=nil,
  #      @zone="PST8PDT", @timezone=#<TZInfo::DataTimezone: PST8PDT>>

#p cron.match?(Time.utc(2019, 1, 1, 0, 0, 0))
p cron.match?(EtOrbi.parse('2019-1-1'))
  # => true

#p cron.match?(Time.new(2019, 1, 1, 0, 0, 0, TZInfo::Timezone.get('UTC')))
p cron.match?(EtOrbi.parse('2019-1-1 UTC'))
  # => true

#p cron.match?(Time.new(2019, 1, 1, 0, 0, 0, TZInfo::Timezone.get('CET')))
p cron.match?(EtOrbi.parse('2019-1-1 ETC'))
  # => true

#p cron.match?(Time.new(2019, 1, 1, 0, 0, 0, TZInfo::Timezone.get('PST8PDT')))
p cron.match?(EtOrbi.parse('2019-1-1 PST8PDT'))
  # => true
jmettraux commented 5 years ago

Closing, moved to https://github.com/floraison/fugit/issues/31

Thanks!