Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

Chronic 0.3.0 Released: Improved Natural Language Date/Time Parsing

By Peter Cooper / October 26, 2010

chronic.pngTom Preston-Werner has pushed out version 0.3.0 of Chronic, the popular natural language date and time parsing library for Ruby. It's a significant release because the last was 0.2.3 back in July 2007! Grab it now with gem install chronic

Despite the long time between releases, Chronic hasn't gone without attention. It's been sitting on GitHub and attracting patches for years, but Tom (who's already pretty busy, y'know, running GitHub) has now decided to bundle it up and push it live.

What does 0.3.0 get you?

  • Improved time-zone support
  • Handles "on" in phrases like "10am on Saturday"
  • Now ignores commas (which could throw it off before)
  • Supports "weekend" and "weekday"
  • Allows numeric timezone offsets (e.g. -0500)
  • Support for seasons
  • "a", "p", "am", and "pm" parsing
  • The typical bugfixes and low level improvements

Chronic is basically a Ruby institution by now (I first posted about it in September 2006!) so check it out. But if you're still itching for other ways to work with dates and times, check out 3 New Date and Time Libraries for Rubyists from May 2010. Tickle is particular interesting as it allows you to parse natural language requests for recurring events rather than single times.

Comments

  1. Jan Friedrich says:

    And non of the libraries support a way to parse other other languages than English. Not even a general approach to support more than one language, all rules are hard coded. :-(

  2. Just Do It says:

    Sounds like an excellent time to submit a patch.

    JUST DO IT!

  3. Drew Dara-Abrams says:

    Great to see a new version. I hope this fixes the daylight savings time bug.

  4. Jan Friedrich says:

    @JustDoIt: Sounds for me more like a complete rewrite (= a new lib) than a patch.

  5. nofxx says:

    I did an experience with i18n of this (sweet) lib:

    http://github.com/nofxx/chronic18n

  6. Jan Friedrich says:

    @nofxx: Cool idea. But I think word wise translation doesn't work for all cases because different languages uses a different sentence construction. For example "3 years ago" is in German "vor 3 Jahren" (years = Jahren, ago = vor).

  7. nofxx says:

    @Jan: Yup, there's such problem in portuguese too, that's why it's a two step translate, first "high level" grammar with regex, then word replacement.
    Would you help me implement/try/test german?

  8. Jan Friedrich says:

    @nofxx: Sounds practicable: "translating the complete phrase to correct English and then call chronic".

    Unfortunately my free time is *very* spare at the moment and the near future, so I can't help so much. But if you explain the approach in detail (for example with test cases for Portuguese or another language) I would look at it, to see if it works with German.

  9. Trey says:

    Tom was joking about this Gem @ RubyConf yesterday. He asked for a show of hands from anybody who knew about our used Chronic (got a good laugh). He also commented on the fact his talk started @ 4:20.

Other Posts to Enjoy

Twitter Mentions