chronic icon indicating copy to clipboard operation
chronic copied to clipboard

Crash when parsing 'Midnight' with negative timezone

Open nagius opened this issue 9 years ago • 1 comments

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 …)

nagius avatar Aug 26 '15 14:08 nagius

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 )

nagius avatar Aug 26 '15 14:08 nagius