3 New Date and Time Libraries for Rubyists

In the UK there's a cliché that goes: "You wait hours for a bus, and then three come along at once!" So it went with these three Ruby date and time libraries. They all made an appearance on RubyFlow last week and are all useful in their own ways, depending on how you're working with dates and times.

ice_cube - Fast querying and expansion of event recurrence rules

ice_cube is a library by John Crepezzi that provides "fast querying and expansion of recurrence rules in Ruby." What this means is that you can create schedules powered by date recurrence rules that can be quite complex (e.g. every 4 years on a Tuesday in the first week of November). Rules like these are defined by chaining methods together, rather than using natural language.

tickle - A natural language parser for recurring events

tickle is a natural language parser for recurring events by Joshua Lippiner that stands in contrast to ice_cube's method driven approach. It depends on the popular chronic natural language date parser and appears (through my experience) to be for Ruby 1.9+ only.

tickle lets you throw it things like every 4 days starting next saturday, every other week, the tenth of the month and similar (there are a lot of examples on tickle's GitHub page). You pass these to the Tickle.parse method and you get the next occurrence of the rule.

tickle isn't particularly mature yet and it only makes it easy to get the next occurrence of your rule, but the developer suggests that once an event has occurred, you automatically run Tickle again to get the next date. In this way, it seems tickle is well suited for situations where only the next occurrence needs to be stored and the rule can be kept in a separate database column or similar.

business_time - Time and date offsets based on "business time/hours"

business_time is a new library that works with the concept of "business time" or "business hours." Rather than just letting you perform operations on dates by absolute numbers of days or hours, you can now work with business days and hours of your own definition. business_time depends heavily on Active Support.

Comments

I made http://github.com/joshbuddy/spanner the other day because I was shocked to discover Chronic didn't parse time spans. I feel like we should bundle up Chronic, Tickle, Spanner et al and make an all-encompassing natural language time parsing library. There is probably a lot of overlap here.

The state of time and date libs for ruby are quite the tangle. Ruby itself has Time, Date and DateTime, plus standard lib extensions 'time.rb' and 'date.rb', and then there's all the ActiveSupport extensions. Then there is tzinfo and also chronic. And I'm sure there are more. Plus these three libs...

I really would be nice if someone very detail minded sat down and just created the ultimate time/date library that took care of all this stuff.

Thanks for the mention. Just FYI to all that I've updated Tickle with a full set of unit tests as well as US Holiday support. I agree with Joshua Hull regarding the overlap and given that Chronic has a number of oddities with it, might be nice to bring them all together. There is a bunch in Tickle, such as the holiday support, that feels like it should be in Chronic as it's more point in time then recurring.