@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
47 lines • 3.63 kB
TypeScript
import { StoredZonedClassification } from "../../types/stored-zoned-classification.js";
import "../../types/index.js";
/**
* Says whether a stored RFC 9557 string with both an offset and a zone still names one
* instant under this host's time zone rules, and gives every reading when it does not.
*
* An offset stored next to a zone is a claim about the zone's rules. When the rules change
* after the string was written, the offset and the zone can disagree (RFC 9557 §3.4), or the
* local time can fall into a new gap or overlap. Each of Temporal's `offset` values
* (`use`, `ignore`, `prefer`, `reject`) is one choice among the readings returned.
*
* Resolution: none. No reading is chosen. An ambiguous or nonexistent local time returns both
* its `earlier` and `later` readings, as `disambiguation` names them, and the instant the
* stored offset gives.
*
* - Five kinds. `valid`: the local time occurs once, at the stored offset. `validInOverlap`: it
* occurs twice and the stored offset picks `instant`, which is `earlier` or `later`.
* `offsetMismatch`: it occurs once, but not at the stored offset. `ambiguous`: it occurs
* twice and the stored offset picks neither. `nonexistent`: it falls in a gap.
* - Every kind carries `atStoredOffset`, the instant `offset: "use"` gives. It differs from
* `instant` when an offset written to the minute matches a zone offset with seconds
* (`Africa/Monrovia`, `-00:45` for `-00:44:30`). An offset written with seconds must match
* exactly.
* - Each reading is a `Temporal.Instant#toString` string ending in `Z`, and each offset is
* `±HH:MM[:SS]`. `storedOffset` keeps the seconds as written, so `-00:45:00` stays
* `-00:45:00`; `zoneOffset` drops a zero seconds part.
* - The result depends on the host's tzdb: the same string can be `valid` on one host and
* `offsetMismatch` on another. On Node, `process.versions.tz` names the release. Browsers
* expose no equivalent.
* - `…Z[zone]` is always `valid` (Temporal reads `Z` as exact, RFC 9557 §3.4 Figure 2), even
* inside an overlap or a gap. `-00:00` is a numeric offset of zero, as Temporal reads it,
* so it can be an `offsetMismatch`.
* - Returns null for a string with no offset, no zone annotation, a bracketed offset in place
* of an IANA zone, an unknown zone, an offset finer than a second, a calendar other than
* `iso8601`, second 60, basic format, a reading outside the instant range, a local date of
* `-271821-04-19` (which Temporal's `prefer` and `reject` refuse), or any non-string input.
*
* @param value RFC 9557 string with a UTC offset and a bracketed IANA time zone
* @returns the classification with every reading as a `Z` instant string, or `null` for any
* other input
*
* @example classifyStoredZoned("2016-12-01T09:00:00+02:00[Europe/Istanbul]") // { kind: "offsetMismatch", storedOffset: "+02:00", zoneOffset: "+03:00", atStoredOffset: "2016-12-01T07:00:00Z", atZoneOffset: "2016-12-01T06:00:00Z" }
* @example classifyStoredZoned("2026-03-29T01:30:00+00:00[Europe/London]") // { kind: "nonexistent", earlier: "2026-03-29T00:30:00Z", later: "2026-03-29T01:30:00Z", atStoredOffset: "2026-03-29T01:30:00Z" }
* @example classifyStoredZoned("2026-10-25T01:30:00+01:00[Europe/London]") // { kind: "validInOverlap", instant: "2026-10-25T00:30:00Z", earlier: "2026-10-25T00:30:00Z", later: "2026-10-25T01:30:00Z", atStoredOffset: "2026-10-25T00:30:00Z" }
* @example classifyStoredZoned("2026-03-29T01:30:00[Europe/London]") // null
*/
export declare function classifyStoredZoned(value: string): StoredZonedClassification | null;