I’ve been troubleshooting a problem on an existing application for the last week or so that deals with the parsing of dates using the Chronic time parsing library. Today the problem magically solved itself, without me doing anything. These types of self solving problems are usually more frustrating than problems you can’t solve at all, so I took a little extra time to experiment with the particular date format I was using and found what might be a problem with the Chronic library when it gets to the “fall back” DST change in the fall.
Do You Observe DST?
It looks like if your local environment is set to a timezone which observes DST, like Eastern Standard Time for instance, you get a chunk of dates around the switch in the fall where Chronic returns nil instead of the correct date. If you’re on a machine where the timezone is set to an area which does not observe DST, like Arizona, you won’t be able to replicate this problem.
Replicating the problem
Install the latest version of Chronic.
$> sudo gem install chronic
Fire up irb and give the following a shot.
1 2 3 4 | require 'chronic' (Date.parse("2009-01-01")..Date.parse("2009-12-31")).each do |d| puts Chronic.parse("next tuesday 6am", :now => d) end |
With ruby 1.8.7 (2008-08-11 patchlevel 72) [i486-linux] on Ubuntu and my timezone set to EST/New York. I see a bunch of Tuesdays and then a blank section around the end of October / beginning of November.
...snip... Tue Oct 20 06:00:00 -0400 2009 Tue Oct 20 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 nil nil nil nil nil nil Tue Nov 03 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 17 06:00:00 -0500 2009 Tue Nov 17 06:00:00 -0500 2009 Tue Nov 17 06:00:00 -0500 2009 ...snip...
If you change your timezone to something like MST/Arizona you’ll see this
...snip... Tue Oct 20 06:00:00 -0400 2009 Tue Oct 20 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Oct 27 06:00:00 -0400 2009 Tue Nov 03 06:00:00 -0500 2009 Tue Nov 03 06:00:00 -0500 2009 Tue Nov 03 06:00:00 -0500 2009 Tue Nov 03 06:00:00 -0500 2009 Tue Nov 03 06:00:00 -0500 2009 Tue Nov 03 06:00:00 -0500 2009 Tue Nov 03 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 10 06:00:00 -0500 2009 Tue Nov 17 06:00:00 -0500 2009 Tue Nov 17 06:00:00 -0500 2009 Tue Nov 17 06:00:00 -0500 2009 ...snip...
What’s the Fix?
None as far as I know. I’m sure one could dig into the internals of the library and figure out how to deal with this problem, but I’m not up for that right now.