@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.
31 lines • 1.86 kB
TypeScript
/**
* RegExp matching ISO 8601 UTC datetime: `<date>T<time>Z` with optional fractional
* seconds, in ISO 8601 extended format. The designator is an upper-case `Z`:
* a lower-case `z`, which RFC 3339 §5.6 and Temporal also read, does not match (`rfc3339DateTime`
* is the RFC 3339 pattern that accepts it).
*
* - Date half: `YYYY-MM-DD` or `±YYYYYY-MM-DD` (6-digit year with sign, never `-000000`,
* which is a Syntax Error in Temporal's `DateYear`).
* - Time half: `HH:mm` with optional `:ss[.fffffffff]` (fractional seconds use `.` or `,`).
* - Second `60` does not match. Temporal's `TimeSecond` admits it, but GMT rejects leap
* seconds because Temporal would read one as `:59`.
* - No numeric offset — only the `Z` UTC designator is accepted.
* - Shape-only validation; real validation is delegated to `Temporal.Instant.from` in
* `isValidUtc`.
*
* Capture groups: 1 month, 2 day, 3 hour. The year, minute, second and fraction are not
* captured.
*
* The written form only, with no RFC 9557 annotation. `isValidUtc` reads more: it matches this
* against the part before the first `[` and lets Temporal read the annotations
* (`"…[u-ca=iso8601]"`, an elective `"…[foo=bar]"`).
*
* @example utcDateTime.test("2024-03-15T14:30:00Z") // true
* @example utcDateTime.test("2024-03-15T14:30z") // false (lower-case z)
* @example utcDateTime.test("2024-03-15T14:30:00.123Z") // true (fractional seconds)
* @example utcDateTime.exec("2024-03-15T14:30:45.5Z")?.slice(1) // ["03", "15", "14"] (month, day, hour)
* @example utcDateTime.test("-000000-01-01T00:00Z") // false (negative zero year)
* @example utcDateTime.test("2024-03-15T14:30:00+00:00") // false (numeric offset)
* @example utcDateTime.test("2024-03-15T14:30:00") // false (no timezone)
*/
export declare const utcDateTime: RegExp;