Parses a locale-formatted string as whichever temporal value it turns out to be — a date, a time, a datetime, or a date range.
Localize.Date.parse/2, Localize.Time.parse/2,
Localize.DateTime.parse/2 and Localize.Interval.parse/2 each parse
one shape and expect the caller to know which. parse/2 here is for
the case where the shape is not known up front: a single text field
that may carry any of "2026-05-16", "14:30", "May 16, 2026 2:30 PM" or "May 5 – May 10, 2026". The caller pattern-matches on the
returned struct to discover what was parsed.
Summary
Functions
Parses a locale-formatted string as a date, time, datetime, or date range — whichever matches.
Functions
@spec parse(String.t(), Keyword.t()) :: {:ok, Date.t() | Time.t() | NaiveDateTime.t() | DateTime.t() | Date.Range.t() | map() | {map(), map()}} | {:error, Exception.t()}
Parses a locale-formatted string as a date, time, datetime, or date range — whichever matches.
Arguments
inputis the string to parse.optionsis a keyword list of options.
Options
:localeis any locale returned byLocalize.all_locale_ids/0. The default isLocalize.get_locale/0.Remaining options are passed to whichever sub-parser matches.
Returns
{:ok, value}wherevalueis aDate.t/0,Time.t/0,NaiveDateTime.t/0,DateTime.t/0orDate.Range.t/0.{:error, exception}, aLocalize.DateTimeParseError.t/0whose:attemptsrecords what each sub-parser reported, or aLocalize.InvalidValueError.t/0ifinputis not a string or an option is malformed.
Examples
iex> Localize.DateTime.Parser.parse("March 22, 2026", locale: :en)
{:ok, ~D[2026-03-22]}
iex> Localize.DateTime.Parser.parse("3:45 PM", locale: :en)
{:ok, ~T[15:45:00]}