Calendrical. Parser
(Calendrical v0.6.0)
Copy Markdown
Unified locale-aware parser that dispatches user input to the appropriate domain parser (date, time, datetime, or date range).
Public entry point: Calendrical.parse/2.
Dispatch strategy
The parser tries each sub-parser in the following order and returns the first success:
Interval — only attempted when the input contains an interval-shaped separator (the locale's
intervalFormatFallbackseparator, or one of–,—,−,〜,~,-,/,to). Cheap fail-fast.Date —
Calendrical.Date.parse/2. Whole-string anchored, so a date+time input won't accidentally match.Time —
Calendrical.Time.parse/2. Whole-string anchored, so a date-only input won't match (no:).DateTime —
Calendrical.DateTime.parse/2. The most expensive (it splits on every glue separator position and runs the date+time parsers on each half), so it runs last as a fallback for inputs that carry both a date and a time.
The order encodes a tiebreaker preference: for ambiguous inputs (e.g. a bare 4-digit year that could be a date or a time) the date interpretation wins.
Summary
Functions
Parses input 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()} | {:error, Exception.t()}
Parses input as a date, time, datetime, or date range — whichever
matches.
See Calendrical.parse/2 for the public contract.