floraison / fugit

time tools (cron, parsing, durations, ...) for Ruby, rufus-scheduler, and flor
MIT License
355 stars 29 forks source link

UTC cron next_time should be a UTC time, not a local time #12

Closed jmettraux closed 5 years ago

jmettraux commented 5 years ago
require 'fugit'

#ENV['TZ'] = 'Asia/Shanghai'
#ENV['TZ'] = 'CST'

EtOrbi._make_info

puts "---"

p Time.now
p Time.now.utc
cron = Fugit.do_parse_cron('0 0 1 1 *')
p cron
p cron.next_time.to_s
p cron.next_time.utc.to_s

puts "---"

p Time.now
p Time.now.utc
cron = Fugit.do_parse_cron('0 0 1 1 * UTC')
p cron
p cron.next_time.to_s
p cron.next_time.utc.to_s
(secs:1546413051.166213,utc~:"2019-01-02 07:10:51.1662130355834961",ltz~:"JST")
(etz:nil,tnz:"JST",tzid:nil,rv:"2.3.7",rp:"x86_64-darwin17",
  win:false,rorv:nil,astz:nil,eov:"1.1.6",eotnz:#<TZInfo::TimezoneProxy: Asia/Tokyo>,
  eotnfz:"+0900",eotlzn:"Asia/Tokyo",debian:nil,centos:nil,osx:"zoneinfo/Asia/Tokyo")
---
2019-01-02 16:10:51 +0900
2019-01-02 07:10:51 UTC
#<Fugit::Cron:0x00007f97d51fb750 @original="0 0 1 1 *", @cron_s=nil,
  @seconds=[0], @minutes=[0], @hours=[0], @monthdays=[1], @months=[1], @weekdays=nil,
  @zone=nil, @timezone=nil>
"2020-01-01 00:00:00 +0900"
"2019-12-31 15:00:00 UTC"
---
2019-01-02 16:10:51 +0900
2019-01-02 07:10:51 UTC
#<Fugit::Cron:0x00007f97d3c665e8 @original="0 0 1 1 * UTC", @cron_s=nil,
  @seconds=[0], @minutes=[0], @hours=[0], @monthdays=[1], @months=[1], @weekdays=nil,
  @zone="UTC", @timezone=#<TZInfo::DataTimezone: UTC>>
"2020-01-01 00:00:00 +0900"
"2019-12-31 15:00:00 UTC"

The second p cron.next_time.to_s should be in the UTC timezone.

As seen in gh-11.

jmettraux commented 5 years ago

Planning to fix/change that for the upcoming 1.2.0.

1.2.x since it is changing the way it reacts to explicit timezones.

jmettraux commented 5 years ago

Released as part of 1.1.8