Calendrical. DateTime. Parser
(Calendrical v0.5.0)
Copy Markdown
Locale-aware parser for user-typed date-time strings.
Public entry point: Calendrical.DateTime.parse/2.
Strategy:
Try bare ISO-8601 (
YYYY-MM-DDTHH:MM:SS[.frac][Z|±HH:MM]). This is the wire format and always works.Otherwise, consult the locale's CLDR date-time glue pattern (
{1}, {0}inen,{1} {0}inja, etc.), split the input on the literal glue separator, and delegate toCalendrical.Date.parse/2andCalendrical.Time.parse/2for the two halves.
Implements the parts of TR35 §Parsing Dates
Times
that apply to date+time input. Time-zone resolution is
documented as a follow-up — when the input carries a Z or
±HH:MM suffix that ISO-8601 already accepts, we honour it;
named timezone suffixes (EST, Asia/Tokyo, etc.) need
per-zone IANA-database integration which lives outside this
parser.
Returns
{:ok, NaiveDateTime.t()}when no zone info was present.{:ok, DateTime.t()}when the input carried an offset orZandCalendar.DateTime.from_iso8601/1could resolve it.{:error, Calendrical.DateTimeParseError.t()}on failure.
Summary
Functions
Parses input as a locale-formatted datetime string.
Functions
@spec parse(String.t(), Keyword.t()) :: {:ok, NaiveDateTime.t() | DateTime.t()} | {:error, Exception.t()}
Parses input as a locale-formatted datetime string.
See Calendrical.DateTime.parse/2 for the public contract.