chronic
https://github.com/mojombo/chronic
Ruby
Chronic is a pure Ruby natural language date parser.
Chronic::Parser#initialize
options - An optional Hash of configuration options:
:context - If your string represents a birthday, you can set
this value to :past and if an ambiguous string is
given, it will assume it is in the past.
:now - Time, all computations will be based off of time
instead of Time.now.
:hours24 - Time will be parsed as it would be 24 hour clock.
:week_start - By default, the parser assesses weeks start on
sunday but you can change this value to :monday if
needed.
:guess - By default the parser will guess a single point in time
for the given date or time. If you'd rather have the
entire time span returned, set this to false
and a Chronic::Span will be returned. Setting :guess to :end
will return last time from Span, to :middle for middle (same as just true)
and :begin for first time from span.
:ambiguous_time_range - If an Integer is given, ambiguous times
(like 5:00) will be assumed to be within the range of
that time in the AM to that time in the PM. For
example, if you set it to `7`, then the parser will
look for the time between 7am and 7pm. In the case of
5:00, it would assume that means 5:00pm. If `:none`
is given, no assumption will be made, and the first
matching instance of that time will be used.
:endian_precedence - By default, Chronic will parse "03/04/2011"
as the fourth day of the third month. Alternatively you
can tell Chronic to parse this as the third day of the
fourth month by setting this to [:little, :middle].
:ambiguous_year_future_bias - When parsing two digit years
(ie 79) unlike Rubys Time class, Chronic will attempt
to assume the full year using this figure. Chronic will
look x amount of years into the future and past. If the
two digit year is `now + x years` it's assumed to be the
future, `now - x years` is assumed to be the past.Edit
git clone [email protected]:mojombo/chronic.git
cd chronic
open lib/chronic/parser.rb
Contribute
# Make a new branchgit checkout -b -your-name--update-docs-Chronic--Parser-initialize-for-pr
# Commit to gitgit add lib/chronic/parser.rbgit commit -m "better docs for Chronic::Parser#initialize"
# Open pull requestgem install hub # on a mac you can `brew install hub`
hub fork
git push <your name> -your-name--update-docs-Chronic--Parser-initialize-for-pr
hub pull-request
# Celebrate!