Reads the text of a date, a time, a date and time, or a duration, and finds out which of the five it is.
The string of an @"..." literal does not say what it denotes, so the kind is chosen
by its shape (notes 01, A32):
- an optional
-andPis a duration, a years and months duration when it has years or months only and a days and time duration otherwise; - a date, a
T, and a time is a date and time; - a date alone is a date;
hh:is a time.
Each kind is then read by its own parse/1, which has the rules for the string and
returns :error for one that is not a valid value of the kind, as @"2020-13-45"
or @"25:00:00". A string of none of these shapes is :error too.
Summary
Functions
Parses the text of a temporal value of any kind.
Types
@type t() :: Date.t() | Feel.Value.Time.t() | Feel.Value.DateTime.t() | Feel.Value.YearsAndMonthsDuration.t() | Feel.Value.DaysAndTimeDuration.t()
A date, a time, a date and time, or a duration.
Functions
Parses the text of a temporal value of any kind.
iex> Feel.Value.Temporal.parse("2019-03-31")
{:ok, ~D[2019-03-31]}
iex> {:ok, %Feel.Value.Time{hour: 23}} = Feel.Value.Temporal.parse("23:59:00z")
iex> {:ok, %Feel.Value.DateTime{}} = Feel.Value.Temporal.parse("2012-12-24T23:59:00")
iex> Feel.Value.Temporal.parse("PT5H")
{:ok, Feel.Value.DaysAndTimeDuration.new(18_000)}
iex> Feel.Value.Temporal.parse("-P1Y")
{:ok, %Feel.Value.YearsAndMonthsDuration{months: -12}}
iex> Feel.Value.Temporal.parse("2020-13-45")
:error
iex> Feel.Value.Temporal.parse("yesterday")
:error