I have been using Chronic successfully in my Rails app for a few weeks. I haven't been doing anything fancy with it, just using it to parse basic time inputs like '1:21pm' or '1440' etc. Everything was working fine up until today when I ran my test suite and came across a very odd failure.
These all work:
Chronic.parse('1:21am')
=> 2016-10-02 00:21:00 +1000
Chronic.parse('0121')
=> 2016-10-03 01:21:00 +1100
Chronic.parse('0021')
=> 2016-10-03 00:21:00 +1100
Chronic.parse('1:21 AM')
=> 2016-10-02 00:21:00 +1000
However 12:21 AM
returns nil:
Chronic.parse('12:21 AM')
=> nil
In my code I'm actually doing a strftime
to strip out the date and just keep the time because that's all I care about. But naturally that doesn't work when Chronic returns nil
.
self.time = Chronic.parse(time).try(:strftime, '%l:%M %p')
What's interesting is that this morning daylight savings kicked in for my timezone, Sydney. I haven't changed anything else around this code for a while, so my guess is that it's related.