mojombo / chronic

Chronic is a pure Ruby natural language date parser.
http://injekt.github.com/chronic
MIT License
3.24k stars 458 forks source link

Can't parse negative offsets with Active Support 4.2.7.1 #345

Open ren90 opened 7 years ago

ren90 commented 7 years ago

Hey guys,

I'm trying to upgrade my Active Support to 4.2.7.1 but then Chronic can no longer parse negative offsets (when rewinding from 00, in other words, when I parse a negative amount of minutes, and the current time has 0 minutes, it breaks). This is due to the fact that Active Support deprecated the Time.utc_time method (called in the Time.local method, used by Chronic) in favour of Time.utc that does not accept negative offsets. This also happens without Active Support, when basing on the Ruby Time class.

Example:

#Timecop for freezing time where the bug occurs
require 'timecop'
require 'chronic'

#lets set a timestamp that has zero minutes
Timecop.freeze('2016-01-01 14:00:49')
#lets ask for the last minute
Chronic.parse('last minute')
#BAM

#lets set a timestamp that hasn't zero minutes
Timecop.freeze('2016-01-01 00:33:49')
#lets ask for the last minute
Chronic.parse('last minute')
#NICES

#lets set a timestamp that has zero hours
Timecop.freeze('2016-01-01 00:14:49')
#lets ask for the last minute
Chronic.parse('last hour')
#BAM

#lets set a timestamp that hasn't zero hours
Timecop.freeze('2016-01-01 14:00:49')
#lets ask for the last minute
Chronic.parse('last hour ')
#NICES

Thanks in advance, Best regards

davispuh commented 7 years ago

Seems to work in my rewrite branch