UNPKG

@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.

51 lines • 3.23 kB
import { Temporal } from "./temporal.js"; /** * Second `60` in the time of day, before any `[`: `T`, `t` or space separator, extended or basic * digits. Temporal's ParseISODateTime clamps it to `:59`; GMT's Plain date-time inputs reject it * (`isValidDateTime`, a duration `relativeTo`). Unlike `regex/leap-second.ts`, no designator is * required, because a Plain string has none. */ export declare const temporalStringLeapSecond: RegExp; /** * Parse a GMT calendar date string into a Temporal.PlainDate, exactly as `Temporal.PlainDate.from` * reads it, restricted to GMT's written shape and GMT's calendars. Throws on invalid input — callers * wrap this in try-catch per GMT's sentinel contract. * * - The whole string must be GMT's strict extended date (`plainDate`) or date-time * (`plainDateTime`), as `isValidDate` and `isValidDateTime` require, optionally followed by one * calendar annotation (`[u-ca=hebrew]`, or critical `[!u-ca=hebrew]`) and nothing else. Basic * format (`20241003`), a space or lower-case `t` separator and a UTC offset are rejected, * although `Temporal.PlainDate.from` reads them, and so is every other annotation: a time zone * (`[Europe/Helsinki]`, `[!Not/AZone]`, `[+02:00]`), an elective `[foo=bar]` and a second * `u-ca`. Only then does Temporal read the string. * - An ISO date with a calendar annotation (`"2024-10-03[u-ca=hebrew]"`, which is what * `Temporal.PlainDate#toString()` writes). The digits are always the ISO date; the annotation * names the calendar (RFC 9557 §3.3). * - A date-time is read as its date, as `Temporal.PlainDate.from` reads it * (`"2024-10-03T14:30[u-ca=hebrew]"` is 2024-10-03 in Hebrew): the time is dropped. A leap * second (second `60`) is rejected, as every GMT Plain date-time input rejects it. * - `Temporal.PlainDate.from` canonicalizes the calendar id (`HEBREW` → `hebrew`, `islamicc` → * `islamic-civil`, `ethiopic-amete-alem` → `ethioaa`). * - The calendar must be a `CalendarSystem`. Temporal also knows `chinese`, `dangi`, `islamic` and * `islamic-rgsa`, which GMT does not support (`chinese` and `dangi`: hosts print different dates, * compat D33). * - The result computes in `computationCalendarId(calendar)`: `"ethiopic"` and `"coptic"` are read * in `"ethioaa"`, so callers that write a string back take the calendar from * `calendarSystemOfDateValue(value)`, not from `date.calendarId`. * * @param value an extended ISO date or date-time, optionally with one calendar annotation * @returns the Temporal.PlainDate, in the computation calendar */ export declare function parseCalendarDateValue(value: string): Temporal.PlainDate; /** * The check behind `isValidCalendarDate`: the `PlainDate` `parseCalendarDateValue` reads, or * `null` where it throws. * * @param value the candidate; a value that is not a non-empty string is not a calendar date * @returns the `PlainDate` in the computation calendar, else `null` * * @example calendarDateOf("2024-10-03[u-ca=hebrew]")?.calendarId // "hebrew" * @example calendarDateOf("2024-02-30") // null * @example calendarDateOf(null) // null */ export declare function calendarDateOf(value: unknown): Temporal.PlainDate | null;