Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezone ignored in cron.match? #21

Closed
assembler opened this issue Aug 29, 2019 · 4 comments
Closed

Timezone ignored in cron.match? #21

assembler opened this issue Aug 29, 2019 · 4 comments
Assignees

Comments

@assembler
Copy link

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 jmettraux self-assigned this Aug 29, 2019
@jmettraux
Copy link
Member

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
Copy link
Author

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

@jmettraux
Copy link
Member

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
Copy link
Member

Closing, moved to floraison/fugit#31

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants