chronic
chronic copied to clipboard
Possible daylight savings time issue for March 10 in AST (Rails)
When trying to parse "March 10th at 12:30pm" in Atlantic Time it's returning March 11th at 12:30am.
Time.zone = 'Atlantic Time (Canada)'
Chronic.time_class = Time.zone
Chronic.parse('March 10th at 12:30pm')
#=> Mon, 11 Mar 2013 00:30:00 ADT -03:00
Everything on March 10th, from 12pm to 12:59pm is moving ahead to March 11th from 12am to 12:59am.
Rails 3.2.12 Chronic 0.9.0 and 0.9.1
+1 I have the same issue.
1.9.3p362 :021 > Time.current => Tue, 12 Mar 2013 11:01:30 GMT +00:00 1.9.3p362 :017 > Time.zone = "London" => "London" 1.9.3p362 :018 > Chronic.time_class = Time.zone => (GMT+00:00) London 1.9.3p362 :019 > Chronic.parse("April 1st at 9am") => Mon, 01 Apr 2013 09:00:00 BST +01:00 1.9.3p362 :020 > Chronic.parse("20 days from now at 9am") => Mon, 01 Apr 2013 10:00:00 BST +01:00
Interestingly, specifying "April 1st" works fine whereas "20 days from now" doesn't work.
Chronic 0.9.1 Rails 3.2.6
+1 same issue here. EST Time zone.
FWIW still not fixed, but for me it only seems to happen on noon the day of the switch:
2.2.1 :001 > Chronic.parse("2016-03-13 12:29:14 PM")
=> 2016-03-14 00:29:14 -0700
2.2.1 :002 > Chronic.parse("2016-03-14 12:29:14 PM")
=> 2016-03-14 12:29:14 -0700
2.2.1 :003 > Chronic.parse("2016-03-12 12:29:14 PM")
=> 2016-03-12 12:29:14 -0800
2.2.1 :005 > Chronic.parse("2016-03-13 1:29:14 PM")
=> 2016-03-13 13:29:14 -0700
2.2.1 :006 > Chronic.parse("2016-03-13 11:29:14 PM")
=> 2016-03-13 23:29:14 -0700
Anyone found a workaround, or a fork that works, or an alternate library?
Can reproduce for March 10th, 2019 during the noon-1300 hour just as @kueda mentioned:
> Chronic.time_class
=> Time
> Chronic.time_class = Time.zone
=> #<ActiveSupport::TimeZone:0x00007f913dda7638 @name="Mountain Time (US & Canada)", @utc_offset=nil, @tzinfo=#<TZInfo::TimezoneProxy: America/Denver>>
At this line:
https://github.com/mojombo/chronic/blob/2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c/lib/chronic/repeaters/repeater_day_portion.rb#L74
> @now
=> Sun, 10 Mar 2019 00:00:00 MST -07:00
> @range
=> 43200..86399
> Chronic.construct(@now.year, @now.month, @now.day)
=> Sun, 10 Mar 2019 00:00:00 MST -07:00
> Chronic.construct(@now.year, @now.month, @now.day) + @range.begin
=> Sun, 10 Mar 2019 13:00:00 MDT -06:00
The addition of 12 hours to midnight (43200 seconds) doesn't account for the 1 hour gained because of the DST switch. Should really be adding "11" hours, not "12" on this day.
PR with fix: #391