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

Chronic.parse("today 11:00am") returns nil on 2011-11-06 #74

Closed
madeofstars0 opened this issue Nov 6, 2011 · 11 comments
Closed

Chronic.parse("today 11:00am") returns nil on 2011-11-06 #74

madeofstars0 opened this issue Nov 6, 2011 · 11 comments
Labels

Comments

@madeofstars0
Copy link

I have been having issues around daylight savings time changes with Chronic calls. Last sunday I was having issues with Chronic returning nil, but I didn't capture any way to reproduce the error. I had problems with Chronic again today, here is what I was noticing in my Rails 3.0.10 app (MRI ruby 1.9.2 and 1.9.3)

Time.zone = "Central Time (US & Canada)"
Chronic.time_class = Time.zone
Chronic.parse("today 11:00am") # => nil
Chronic.parse("today 10:59am") # => Sun, 06 Nov 2011 10:59:00 CST -06:00
Chronic.parse("today 11:59am") # => nil
Chronic.parse("today 12:00pm") # => Sun, 06 Nov 2011 12:00:00 CST -06:00 

I was trying to reproduce Chronic returning me nil on 10-30 using Timecop, but was unable to reproduce the errors, so I don't know if you will be able to use something like Timecop to validate this issue after today.

I also did this little test in irb (ruby 1.9.3)

require 'chronic'
Chronic.parse("today 11:00am") # => nil

My servers (ruby 1.9.2) are running with the timezone set to GMT at the OS level, the development machines (1.9.2 and 1.9.3) are set to Central Time at the OS level.

@amateurhuman
Copy link

I was having a similar problem in 0.6.4 and updated to 0.6.6 which fixed the issue. Your problem seems to also be fixed in 0.6.6.

main:0> Time.zone = "Central Time (US & Canada)" #=> "Central Time (US & Canada)"
main:0> Chronic.time_class = Time.zone #=> (GMT-06:00) Central Time (US & Canada)
main:0> Chronic.parse("today 11:00am") #=> Tue, 06 Dec 2011 11:00:00 CST -06:00
main:0> Chronic.parse("today 10:59am") #=> Tue, 06 Dec 2011 10:59:00 CST -06:00
main:0> Chronic.parse("today 11:59am") #=> Tue, 06 Dec 2011 11:59:00 CST -06:00
main:0> Chronic.parse("today 12:00pm") #=> Tue, 06 Dec 2011 12:00:00 CST -06:00

@frankchendev
Copy link

I still had similar problem in 0.6.6 too. It could be an issue from daylight saving time transition:

Time.zone
#<ActiveSupport::TimeZone:0x620b8972 @name="America/New_York", @current_period=#<TZInfo::TimezonePeriod: #<TZInfo::TimezoneTransitionInfo: #<TZInfo::TimeOrDateTime: 1320559200>,#<TZInfo::TimezoneOffsetInfo: -18000,0,EST>>,#<TZInfo::TimezoneTransitionInfo: #<TZInfo::TimeOrDateTime: 1331449200>,#<TZInfo::TimezoneOffsetInfo: -18000,3600,EDT>>>, @utc_offset=nil, @tzinfo=#<TZInfo::TimezoneProxy: America/New_York>>

Chronic.parse('sunday next week', {:now=>Time.zone.parse('11/01/2011')})
nil

Chronic.parse('sunday next week', {:now=>Time.zone.parse('10/24/2011')})
Sun Nov 06 11:30:00 -0500 2011

Chronic.parse('sunday next week')
Sun Dec 25 12:00:00 -0500 2011

(I specified the :now option to make reproducing easier.)

@duelinmarkers
Copy link

Presumably the same issue, today we have similar behavior:

>> Chronic.debug = true
=> true

>> Chronic.parse "yesterday at 11:59", :now => Time.zone.parse('3/13/2012') # tomorrow we'll be ok
+---------------------------------------------------
| last(grabber-last) day(repeater-day) at(separator-at) 11:59(repeater-time-43140?) 
+---------------------------------------------------
-anchor
--(Mon Mar 12 00:00:00 -0400 2012..Tue Mar 13 00:00:00 -0400 2012)
--(Mon Mar 12 00:00:00 -0400 2012..Tue Mar 13 00:00:00 -0400 2012)
--(Mon Mar 12 06:00:00 -0400 2012..Mon Mar 12 18:00:00 -0400 2012)
--(Mon Mar 12 11:59:00 -0400 2012..Mon Mar 12 11:59:01 -0400 2012)
=> Mon Mar 12 11:59:00 -0400 2012

>> Chronic.parse "yesterday at 11:59", :now => Time.zone.parse('3/12/2012') # today we get nil
+---------------------------------------------------
| last(grabber-last) day(repeater-day) at(separator-at) 11:59(repeater-time-43140?) 
+---------------------------------------------------
-anchor
--(Sat Mar 10 23:00:00 -0500 2012..Mon Mar 12 00:00:00 -0400 2012)
--(Sat Mar 10 23:00:00 -0500 2012..Mon Mar 12 00:00:00 -0400 2012)
=> nil

@duelinmarkers
Copy link

What I think this comes down to is that Chronic::RepeaterDay tries to provide the next or previous day's date by adding 86,400 seconds, which doesn't work on the 23- or 25-hour days we have at DST changes. In the case above, Chronic::RepeaterDayPortion then uses just the year, month, and day to construct a new time (in this), whacking off the 23:00:00 hours and giving you a full day too early. That then leaves a range outside the span we started with, which leads to find_within giving up and returning nil.

@jwigal
Copy link

jwigal commented Mar 14, 2012

This might be related... I saw an error on Sunday, where Chronic was interpreting 12:30 PM as 12:30 AM on Sunday:

ree-1.8.7-2010.02 :011 > Chronic.parse("12:30 PM", :now => Time.local(2012, 3, 11, 17, 0, 0, 0))
 => Mon Mar 12 00:30:00 -0400 2012 
ree-1.8.7-2010.02 :012 > 

@jwigal
Copy link

jwigal commented May 11, 2012

Similar problem, slightly different can be found here:

#87

@leejarvis
Copy link
Collaborator

This appears to be fixed in the latest revision of Chronic. Please re-open if you can reproduce these errors.

@jwigal
Copy link

jwigal commented Jan 27, 2013

The original issue may be resolved, but the other relate examples are unfortunately still not resolved.

jeff-wigals-macbook-pro:chronic [master] jeff$ gem list --local | grep chronic
chronic (0.9.0)
jeff-wigals-macbook-pro:chronic [master] jeff$ irb -Ilib
1.9.3-p194 :001 > require 'chronic'
 => true 
1.9.3-p194 :002 > Chronic.debug = true
 => true 
1.9.3-p194 :003 > Chronic.parse "yesterday at 11:59", :now => Time.parse('2012-03-13')
-anchor
Handler: handle_r
Handler-class: Chronic::RepeaterDay
--(2012-03-12 00:00:00 -0400..2012-03-13 00:00:00 -0400)
--(2012-03-12 00:00:00 -0400..2012-03-13 00:00:00 -0400)
--(2012-03-12 06:00:00 -0400..2012-03-12 18:00:00 -0400)
--(2012-03-12 11:59:00 -0400..2012-03-12 11:59:01 -0400)
+---------------------------------------------------
| [last(grabber-last) , day(repeater-day) , at(separator-at) , 11:59(repeater-time-43140?, timezone) ]
+---------------------------------------------------
 => 2012-03-12 11:59:00 -0400 
1.9.3-p194 :004 > Chronic.parse "yesterday at 11:59", :now => Time.parse('2012-03-12')
-anchor
Handler: handle_r
Handler-class: Chronic::RepeaterDay
--(2012-03-10 23:00:00 -0500..2012-03-12 00:00:00 -0400)
--(2012-03-10 23:00:00 -0500..2012-03-12 00:00:00 -0400)
+---------------------------------------------------
| [last(grabber-last) , day(repeater-day) , at(separator-at) , 11:59(repeater-time-43140?, timezone) ]
+---------------------------------------------------
 => nil 

Oops, this shouldn't return nil.

1.9.3-p194 :005 > Chronic.parse "12:30 PM", :now => Time.local(2012, 3, 11, 17, 0, 0, 0)
-anchor
Handler: handle_r
Handler-class: Chronic::RepeaterDayPortion
--(2012-03-11 13:00:00 -0400..2012-03-12 00:59:59 -0400)
--(2012-03-11 13:00:00 -0400..2012-03-12 00:59:59 -0400)
--(2012-03-12 00:30:00 -0400..2012-03-12 00:30:01 -0400)
+---------------------------------------------------
| [12:30(repeater-time-1800?, timezone) , pm(repeater-dayportion-pm) ]
+---------------------------------------------------
 => 2012-03-12 00:30:00 -0400 
1.9.3-p194 :006 > 

Should return:

 => 2012-03-12 12:30:00 -0400 

I think @duelinmarkers is correct, the underlying issue is adding 86,400 seconds to advance to the next day, which just doesn't work on the days that have 23 or 25 hours.

@mikeraimondi
Copy link

I can confirm that this issue still exists. Chronic.parse('12:00') returns nil on March 8, 2015.

@davispuh
Copy link
Collaborator

that's because of DST, currently no support for it, there's loads of such issues #147, #177, #179, #222, #228, #282
they all will be probably fixed once DST is properly implemented.

@simonmorley
Copy link

+1

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

No branches or pull requests

9 participants