mojombo/chronic

Namechronic
DescriptionChronic is a pure Ruby natural language date parser.
LanguageRuby
Topics
Watchers3,120
Forks463
Open issues147
Last push10/15/2020 10:38:07 AM +00:00
Github URLhttps://github.com/mojombo/chronic
Clone URLhttps://github.com/mojombo/chronic.git
SSH URL[email protected]:mojombo/chronic.git

Most active issues

Topic# Comments
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 `
'



Read comments
25
Moved all english hardcoded regexes/strings to a locale hash, which is in its separate file.

Created a separate gem to maintain other locales: https://github.com/luan/chronic-l10n


Read comments
23

1.9.3p286 :036 > Time.zone
=> (GMT+10:00) Brisbane
1.9.3p286 :037 > Time.zone.parse '9am'
=> Thu, 04 Apr 2013 09:00:00 EST +10:00
1.9.3p286 :038 > Chronic.parse '9am'
=> Thu, 04 Apr 2013 09:00:00 EST +10:00
1.9.3p286 :039 > Time.zone = 'Greenwich'
=> "Greenwich"
1.9.3p286 :040 > Time.zone.parse '9am'
=> Thu, 04 Apr 2013 09:00:00 GMT +00:00
1.9.3p286 :041 > Chronic.parse '9am'
=> Thu, 04 Apr 2013 09:00:00 EST +10:00
1.9.3p286 :042 > Chronic.time_class
=> (GMT+10:00) Brisbane


My rails app sets Time.zone on a user level, using an `around_filter` based on the current user. This causes subtle problems in Chronic parsing, which is why I've (reluctantly) stuck to `Time.zone.parse` so far.

The only solution I can think of is to `Chronic.time_class` on each request, after changing the `Time.zone`. But that makes things harder to test and doesn't feel right. I wonder if there is a better way of doing it?


Read comments
23
I love Chronic. It's wonderful. But it looks like this version 3.0 with time zone support was never pushed to Rubyforge -- which means it never made it to Gemcutter. The standard 'gem install chronic' is now years out of date and doesn't have the time zone features built in. I hope you won't mind taking a minute or two to update it on the new canonical gem source.


Read comments
16
Parsing `6pm` finds a future time regardless of `context`, and so do many or most times without meridiem (`6:00`).


>> Time.now
=> Mon Aug 08 09:13:01 -0700 2011


Past parses to 9 hours ahead:


?> Chronic.parse('6pm',:context => :past)
=> Mon Aug 08 18:00:00 -0700 2011


that is, the same as future:


>> Chronic.parse('6pm', :context => :future)
=> Mon Aug 08 18:00:00 -0700 2011


Providing a time with no meridiem parses correctly in the past:


>> Chronic.parse('6:00', :context => :past)
=> Mon Aug 08 06:00:00 -0700 2011


.. but I believe it may be because 6 AM in the past happens to be closer to current time. When I try a different time without a meridiem, it chooses a future one and ignores `context`:


>> Chronic.parse('2:00', :context => :past)
=> Mon Aug 08 14:00:00 -0700 2011


All tests with 0.6.2. Thanks.


Read comments
15
I am trying to find a way of getting the last day of a month, for example: last day of last month

I have tried various combos but cannot find anything. I have had a look through the code and it is a bit beyond me. Does anyone know if this can be done?

I should mention that the first day works. Something like "last month first day" or "first day of last month" is fine.


Read comments
13
I often find that I want an error to be raised when chronic can't parse a time string. Chronic.parse! will raise a RuntimeError if the time string can't be parsed.


Read comments
12
The documented way of setting timezones on constructing times is to use ActiveSupport TimeZone like so:


>> Time.zone = "UTC"
>> Chronic.time_class = Time.zone
>> Chronic.parse("June 15 2006 at 5:45 AM")
=> Thu, 15 Jun 2006 05:45:00 UTC +00:00


However, the consequence of this is that (at least in rails), `Time.zone=` changes the presumed time zone throughout an application.

Is there any way to provide time zone as an option per parse? Like:


`Chronic.parse("December 21st at 4PM", :time_zone => "Central Time (US & Canada)")`



Read comments
12
On my gentoo machine running on master with both ruby19 and jruby I got two failures:

bash
1) Failure:
test_guess(TestChronic) [/home/lsl/michel/prof/ruby/overlay/dev-ruby/chronic/chronic/test/test_chronic.rb:55]:
Expected: 2006-11-16 00:00:00 -0200
Actual: 2006-11-16 00:30:00 -0200

2) Failure:
test_parse_guess_r(TestParsing) [/home/lsl/michel/prof/ruby/overlay/dev-ruby/chronic/chronic/test/test_parsing.rb:481]:
Expected: 2006-11-16 00:00:00 -0200
Actual: 2006-11-16 00:30:00 -0200



But if I run the tests with "TZ=UTC", all the tests passes. Am I doing something wrong?


Read comments
11
I have been having issues around daylight savings time changes with Chronic calls. Last sunday I was having issues with Chronic returning nil, but I didn't capture any way to reproduce the error. I had problems with Chronic again today, here is what I was noticing in my Rails 3.0.10 app (MRI ruby 1.9.2 and 1.9.3)


Time.zone = "Central Time (US & Canada)"
Chronic.time_class = Time.zone
Chronic.parse("today 11:00am") # => nil
Chronic.parse("today 10:59am") # => Sun, 06 Nov 2011 10:59:00 CST -06:00
Chronic.parse("today 11:59am") # => nil
Chronic.parse("today 12:00pm") # => Sun, 06 Nov 2011 12:00:00 CST -06:00


I was trying to reproduce Chronic returning me nil on 10-30 using Timecop, but was unable to reproduce the errors, so I don't know if you will be able to use something like Timecop to validate this issue after today.

I also did this little test in irb (ruby 1.9.3)


require 'chronic'
Chronic.parse("today 11:00am") # => nil


My servers (ruby 1.9.2) are running with the timezone set to GMT at the OS level, the development machines (1.9.2 and 1.9.3) are set to Central Time at the OS level.


Read comments
11