Calendrical.Parser (Calendrical v0.9.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:

  1. Interval — only attempted when the input contains an interval-shaped separator (the locale's intervalFormatFallback separator, or one of , , , , ~, -, /, to). Cheap fail-fast.

  2. DateCalendrical.Date.parse/2. Whole-string anchored, so a date+time input won't accidentally match.

  3. TimeCalendrical.Time.parse/2. Whole-string anchored, so a date-only input won't match (no :).

  4. DateTimeCalendrical.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

parse(input, options \\ [])

@spec parse(String.t(), Keyword.t()) ::
  {:ok,
   Date.t()
   | Time.t()
   | NaiveDateTime.t()
   | DateTime.t()
   | Date.Range.t()
   | Date.Range.t()
   | map()
   | {map(), map()}}
  | {:error, Exception.t()}

Parses input as a date, time, datetime, or date range — whichever matches.

See Calendrical.parse/2 for the public contract.