Skip to content

alexduryee/timetwister

Repository files navigation

Build Status Coverage Status

Timetwister

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.

Installation

Add this line to your application's Gemfile:

gem 'timetwister'

And then execute:

$ bundle

Or install it yourself as:

$ gem install timetwister

Usage

Takes a date (or list of dates) as a string, and returns a list of hashes with parsed date data.

Ruby

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"}]

Command Line

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 an Array 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

Contributing

  1. Fork it ( https://github.com/[my-github-username]/timetwister/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Update specs to test for new features (rspec)
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create a new Pull Request

Contributors

About

Powerful Ruby date parser

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages