datify

Datify is a rubygem to convert a string storing a date or a time in a proper Time ruby object. Imagine you have a text file containing a list of string formatted this way ‘day-month-year’ and you want to have fulle featured Time object now you can with datify.

NEWS From the version 0.50 and beyond, you don’t have to call internal Datify::Engine methods anymore, but eventually you may want to use two new methods datify has added to String class.

If you require the datify gem, your strings will acquire:

is_time? - a boolean checking out if the string is a good datetime
to_time  - the core method returning a Time object for the self class

The API now is even easier.

"23-giu-1976".is_time? _~> true_
"23-giu-1976".to_time _1976-06-23 00:00:00 +0200_

Of course you can work in the previous way as well.

require 'datify'

my_date = Datify::Engine.new('16-giu-1976')
puts my_date.date.to_s

That’s it!

Install

You may want to install datify with the following command:

gem install datify

Contributing to datify

Copyright © 2011 Paolo Perego. See LICENSE.txt for further details.