Ruby 1.9.2 Support #11

dmarkow opened this Issue May 24, 2010 · 25 comments


None yet
dmarkow commented May 24, 2010

May not be worth looking into until Ruby 1.9.2 is actually released, but on 1.9.2-head Chronic is having some issues. Main ones I caught:

Chronic.parse("5/24/10") gives my 0010-05-24 instead of 2010-05-24

Chronic.parse("2010-05-24 09:00:00") throws an error now:

TypeError: can't convert Chronic::RepeaterTime::Tick into an exact number
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/repeaters/repeater_time.rb:74:in `+'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/repeaters/repeater_time.rb:74:in `block in next'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/repeaters/repeater_time.rb:67:in `catch'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/repeaters/repeater_time.rb:67:in `next'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/repeaters/repeater_time.rb:107:in `this'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/handlers.rb:318:in `get_anchor'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/handlers.rb:90:in `day_or_time'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/handlers.rb:178:in `handle_sm_sd_sy'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/handlers.rb:193:in `handle_sy_sm_sd'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/handlers.rb:44:in `block in tokens_to_span'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/handlers.rb:40:in `each'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/handlers.rb:40:in `tokens_to_span'
    from /Users/dylan/.rvm/gems/ruby-1.9.2-head/gems/chronic-0.2.3/lib/chronic/chronic.rb:84:in `parse'
    from (irb):4
    from /Users/dylan/.rvm/rubies/ruby-1.9.2-head/bin/irb:17:in `'
ckoehler commented Jun 6, 2010

Same problem here. Thanks for reporting!

alexch commented Jul 16, 2010

Also, reports:

ruby-1.9.2-head > Chronic.parse('3 months ago saturday at 5:00 pm')
TypeError: can't iterate from Time

and I'm getting

can't iterate from Time
activesupport-2.3.8/lib/active_support/core_ext/range/include_range.rb:24:in each' activesupport-2.3.8/lib/active_support/core_ext/range/include_range.rb:24:ininclude?'
activesupport-2.3.8/lib/active_support/core_ext/range/include_range.rb:24:in include?' activesupport-2.3.8/lib/active_support/core_ext/range/include_range.rb:24:ininclude_with_range?'
chronic-0.2.3/lib/chronic/handlers.rb:350:in find_within' chronic-0.2.3/lib/chronic/handlers.rb:326:inget_anchor'
chronic-0.2.3/lib/chronic/handlers.rb:219:in handle_r' chronic-0.2.3/lib/chronic/handlers.rb:224:inhandle_r_g_r'
chronic-0.2.3/lib/chronic/handlers.rb:54:in block in tokens_to_span' chronic-0.2.3/lib/chronic/handlers.rb:50:ineach'
chronic-0.2.3/lib/chronic/handlers.rb:50:in tokens_to_span' chronic-0.2.3/lib/chronic/chronic.rb:84:inparse'

francis commented Jul 28, 2010

easy fix for the this:

@ --- orig/gems/chronic-0.3.0/lib/chronic/handlers.rb  2010-05-03 14:42:38.000000000 -0500
+++ fixed/gems/chronic-0.3.0/lib/chronic/handlers.rb    2010-07-28 11:18:24.000000000 -0500
@@ -387,6 +387,10 @@
+    def in_span?(span, t)
+        t && span && t >= span.begin && t <= span.end
+    end
     # Recursively finds repeaters within other repeaters.
     # Returns a Span representing the innermost time span
     # or nil if no repeater union could be found
@@ -397,8 +401,7 @@
       head, *rest = tags
       head.start = pointer == :future ? span.begin : span.end
       h = head.this(:none)
-      if span.include?(h.begin) || span.include?(h.end)
+      if in_span?(span, h.begin) || in_span?(span, h.end)
         return find_within(rest, h, pointer)
         return nil
AaronH commented Aug 3, 2010

This fixes part of it, but the problem still remains with can't convert Chronic::RepeaterTime::Tick into an exact number

I was able to get it to work by updating the catch(:done) block in the next(pointer) function in repeater_time.rb replacing the all additions of @type with @type.time. So, that section looks like:

if pointer == :future
if @type.ambiguous?
[midnight + @type.time + offset_fix, midnight + half_day + @type.time + offset_fix, tomorrow_midnight + @type.time].each do |t|
(@current_time = t; throw :done) if t >= @now
[midnight + @type.time + offset_fix, tomorrow_midnight + @type.time].each do |t|
(@current_time = t; throw :done) if t >= @now
else # pointer == :past
if @type.ambiguous?
[midnight + half_day + @type.time + offset_fix, midnight + @type.time + offset_fix, yesterday_midnight + @type.time + half_day].each do |t|
(@current_time = t; throw :done) if t <= @now
[midnight + @type.time + offset_fix, yesterday_midnight + @type.time].each do |t|
(@current_time = t; throw :done) if t <= @now

francis commented Aug 3, 2010

Sorry - I meant to post a fix for that too, but came up with something different. Maybe your approach is better though because I ended up patching active support:

--- orig-activesupport-2.3.8/lib/active_support/core_ext/time/calculations.rb   2010-07-15 07:34:32.000000000 -0500
+++ activesupport-2.3.8/lib/active_support/core_ext/time/calculations.rb    2010-07-28 11:26:14.000000000 -0500
@@ -275,7 +275,7 @@
          if ActiveSupport::Duration === other
-            plus_without_duration(other)
+            plus_without_duration(other.to_f)
AaronH commented Aug 5, 2010

Yeah, I looked at doing it that way but it seemed worse.

Ideally, the to_f method on the Tick class would be called and that's all you'd have to do but it doesn't seem to work properly so calling the time element specifically seems to work.

francis commented Aug 5, 2010

I think your way is better. I found a similar patch in the chronic network graph of branches too. Also, I found a better patch than my in_span? patch above. I've merged than into the fork I make of your branch Aaron.

fpauser commented Aug 31, 2010

Have these problems too running chronic with ruby-1.9.2-p0...

AaronH commented Aug 31, 2010

fpauser, if you look at my fork that fixes it.

fguillen commented Nov 2, 2010

I have these problems too, I have to use the AaronH fork.

francis commented Nov 2, 2010

AaronH's fork is what we are using in production, and it has been working great with ruby 1.9.2-p0.


It would be great if AaronH's fork were merged into mainline chronic. This is causing issues that require ugly workarounds since now for example the Whenever gem is requiring aaronh-chronic as its dependency, and ultrasphinx gem requires just 'chronic' and the currently broken on 1.9.2 chronic seems to win. Had to create my own fork of aaronh-chronic, rename it in the gemspec to 'chronic' and bring both copies (of the same code!) into bundler. Please save us from the madness. ;-)

fpauser commented Nov 17, 2010

The AaronH-Fork is used in whenever too. Runs fine in production.
+1 for merging the AaronH fork

billc commented Nov 27, 2010

Has this been integrated to the master? I am receiving the 'iterate Time' error when parsing "tomorrow at 7pm". I tried to get the AaronH fork but getting the error

Source does not contain any versions of 'chronic (>= 0, runtime)'

So I am perplexed. Using 1.9.2 Rails 3.0.3


I was able to get the AaronH fork working but would always rather work with the master branch. +1 for his fix.

samg commented Nov 28, 2010

I just noticed this "Can't iterate Time" issue to when testing a project of mine (which uses Chronic) for 1.9.2 compatibility. It would be great to get this fixed in a new gem release.


+1 for merging AaronH's changes into master, or at least creating a Ruby 1.9.2 branch so that can be referenced in bundler directly like so:

gem "chronic", "0.3.9", :git => "", :branch => "ruby192"

antani commented Dec 17, 2010

How do I install AaronH's fork ? my following Gemfile entry fails :
gem 'chronic', '0.3.9', :git => 'git://'

fails with the following error when I do 'bundle install'

Could not find gem 'chronic (= 0.3.9, runtime)' in git:// (at master).
Source does not contain any versions of 'chronic (= 0.3.9, runtime)'


@antani, without using git, you can just do this for the time being in bundler:

gem "aaronh-chronic", "0.3.9" # for ruby 1.9 compatibility


@antani, btw, you were mostly there with git, try this in bundler if you want it straight from git:

gem "aaronh-chronic", "0.3.9", :git => '' # for ruby 1.9 compatibility

antani commented Dec 17, 2010

After upgrading to aarohn-chronic (via bundle install and later bundle update) I am getting follwing error:
ActionController::RoutingError (uninitialized constant CalendarsController::Chronic):
app/controllers/calendars_controller.rb:4:in <class:CalendarsController>' app/controllers/calendars_controller.rb:1:in<top (required)>'

Do I need to change my code with this change ?

Mange commented Jan 28, 2011

Adding myself to this Issue to get emails on any updates. Sorry for spamming you guys in the process. :-(


Hello folks. Likewise, just want to track updates.

Bumped into this when using Delorean, which relies on Chronic.

@mojombo: You guys must be busy. It would be great if you added a contributor or two to maintain popular projects like this.

fpauser commented Feb 27, 2011

Had problems with Delorean too. The problem is long fixed as it seems - but the fix is not getting pulled-in... this really sucks!

@Mange: Which progress?

Mange commented Feb 28, 2011

@fpauser: I was commenting; everyone got an email even though I had nothing to contribute. The word was "process", not "progress". Read my post again. ;-)


Fixed by @AaronH closed by 3bbfee9

@leejarvis leejarvis closed this May 25, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment