chronic v1.1.2 Chronic
Chronic is a Pure Elixir natural language parser for times and dates
Summary
Functions
Parses the specified time. Will return {:ok, time, utc_offset}
if it knows a time, otherwise {:error, :unknown_format}
Functions
Parses the specified time. Will return {:ok, time, utc_offset}
if it knows a time, otherwise {:error, :unknown_format}
## Examples
ISO8601 times will return an offset if one is specified:
iex> Chronic.parse("2012-08-02T13:00:00")
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 13, min: 0, month: 8, sec: 0, usec: nil, year: 2012}, nil }
iex> Chronic.parse("2012-08-02T13:00:00+01:00")
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 13, min: 0, month: 8, sec: 0, usec: nil, year: 2012}, 3600 }
You can pass an option to define the “current” time for Chronic:
iex> Chronic.parse("aug 2", currently: {{1999, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 0, min: 0, month: 8, sec: 0, usec: 0, year: 1999}, 0 }
All examples here use currently
so that they are not affected by the passing of time. You may leave the currently
option off.
iex> Chronic.parse("aug 2 9am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 0, month: 8, sec: 0, usec: 0, year: 2016}, 0 }
iex> Chronic.parse("aug 2 9:15am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 15, month: 8, sec: 0, usec: 0, year: 2016}, 0 }
iex> Chronic.parse("aug 2nd 9:15am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 15, month: 8, sec: 0, usec: 0, year: 2016}, 0 }
iex> Chronic.parse("aug. 2nd 9:15am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 15, month: 8, sec: 0, usec: 0, year: 2016}, 0 }
iex> Chronic.parse("2 aug 9:15am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 15, month: 8, sec: 0, usec: 0, year: 2016}, 0 }
iex> Chronic.parse("2 aug at 9:15am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 15, month: 8, sec: 0, usec: 0, year: 2016}, 0 }
iex> Chronic.parse("2nd of aug 9:15am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 15, month: 8, sec: 0, usec: 0, year: 2016}, 0 }
iex> Chronic.parse("2nd of aug at 9:15am", currently: {{2016, 1, 1}, {0,0,0}})
{ :ok, %Calendar.NaiveDateTime{day: 2, hour: 9, min: 15, month: 8, sec: 0, usec: 0, year: 2016}, 0 }