A DateTime wrapper with improved date format parsing and fewer surprises.
Developed by the New York Public Library to transform freetext date metadata into machine-readable data.
Add this line to your application's Gemfile:
gem 'timetwister'
And then execute:
$ bundle
Or install it yourself as:
$ gem install timetwister
Takes a date (or list of dates) as a string, and returns a list of hashes with parsed date data.
Returns a list of hashes of parsed date data.
require 'timetwister'
Timetwister.parse("Jun 1898 - [July 4 1900]")
=> [{:original_string=>"Jun 1898 - July 4 1900", :index_dates=>[1898, 1899, 1900], :date_start=>"1898-06-01", :date_end=>"1900-07-04", :date_start_full=>"1898-06-01", :date_end_full=>"1900-07-04", :inclusive_range=>true, :certainty=>"inferred", :test_data=>"330"}]
Returns a JSON object of parsed date data.
$ timetwister 'december 21 2015'
[{"original_string":"december 21 2015","index_dates":[2015],"date_start":"2015-12-21","date_end":"2015-12-21","date_start_full":"2015-12-21","date_end_full":"2015-12-21","inclusive_range":null,"certainty":null,"test_data":"200"}]
Output explanation:
:original_string
is the original input:index_dates
is anArray
of each year encompassed by the provided date range:date_start
and:date_end
are ISO8601 representations of the input date, with no assumed values:date_start_full
and:date_end_full
are ISO8601 representations of the input date in YYYY-MM-DD format (using assumed values when needed):inclusive_range
is whether or not the input value is a range:certainty
is the certainty of the provided date, based on use of flags and punctuation
- Fork it ( https://github.com/[my-github-username]/timetwister/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Update specs to test for new features (
rspec
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request