Calendrical. TimeZone
(Calendrical v0.5.0)
Copy Markdown
Resolve textual time-zone identifiers captured by the parser into UTC offsets.
The resolver tries these strategies in order:
ISO 8601 offset —
Z,±HHMM,±HH:MM,±HH:MM:SS.GMT/UTC format —
GMT,GMT+10,UTC-5:30.IANA region/city —
Asia/Tokyo,America/New_York. Looked up via the host application's installed time-zone database (TzdataorTz) — whichever is loaded at runtime. If neither is loaded, IANA names are rejected (consumer should add:tzdataor:tzas a dependency to support them).Short abbreviation —
PST,EST,JST. Resolved via a small static table for the most common abbreviations. Note that abbreviations are inherently ambiguous (CST could be Central or China Standard); the table picks the most common North-American/Asian/European reading.CLDR locale name —
Pacific Time,Greenwich Mean Time. Looked up viaLocalize's CLDRtimeZoneNamesdata for the parsing locale.
When the parser captures a wall-clock instant alongside an
IANA zone, the resolver uses the instant to pick between
standard / daylight offsets (e.g. 2024-07-15 14:00 America/New_York
→ EDT (-04:00), while 2024-01-15 14:00 America/New_York
→ EST (-05:00)).
Summary
Functions
Resolves zone_string against a wall-clock NaiveDateTime.
Returns the configured time-zone database module, or nil
when neither Tzdata nor Tz is loaded.
Functions
@spec resolve(String.t(), NaiveDateTime.t(), Keyword.t()) :: {:ok, DateTime.t()} | {:error, atom() | Exception.t()}
Resolves zone_string against a wall-clock NaiveDateTime.
Arguments
zone_stringis the captured zone token (e.g."PST","+0530","Asia/Tokyo","Pacific Time").naive_dtis the parsed wall-clock instant. Used to disambiguate standard vs daylight offsets for IANA zones (e.g.America/New_Yorkis-05:00in January and-04:00in July).optionsis a keyword list of options.
Options
:locale— locale to use when looking up CLDR-style names like"Pacific Time". Defaults toLocalize.get_locale/0.
Returns
{:ok, DateTime.t()}when the zone resolves.{:error, reason}when the zone string isn't recognizable.
@spec tz_database() :: module() | nil
Returns the configured time-zone database module, or nil
when neither Tzdata nor Tz is loaded.
Consumers that want IANA name resolution should add one of these to their dependency list. The resolver works without them but rejects IANA names.