chronic
chronic copied to clipboard
Crash when parsing 'Midnight' with negative timezone
Code to reproduce :
require 'time'
require 'chronic'
require 'active_support/all'
now = Time.parse("2015-08-25 02:00:00 +0000")
Chronic.time_class = ActiveSupport::TimeZone.new("Pacific Time (US & Canada)")
Chronic::parse("Midnight", :context => :past, :now => now )
Raise an exception :
[...] chronic/repeaters/repeater_time.rb:111:in `next': Current time cannot be nil at this point (RuntimeError)
Note that it's working fine with positive timezone (GMT, UTC+n …)
I found a workaround. By adding few hours to the 'now' time so it's ahead of the timezone's offset, there is no more issue :
now = Time.parse("2015-08-25 00:00:00 +0000")
now += 12.hours
Chronic.time_class = ActiveSupport::TimeZone.new("Pacific Time (US & Canada)")
Chronic::parse("Midnight", :context => :past, :now => now )