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.

36 lines • 2.13 kB
/** * One unit of GMT's human duration grammar (CORE-85). GMT's own grammar: no standard defines these * strings. Symbols follow the BIPM SI Brochure, 9th ed.: `s` is Table 2 (base units), `ms` is the * milli prefix (Table 7), `min`, `h` and `d` are Table 8; `mo` for a month and the other spellings are a GMT rule. */ export interface HumanDurationUnit { /** Position in the left-to-right order: 1 year to 8 millisecond. Each rank at most once. */ readonly rank: number; /** The ISO 8601 designator the unit becomes (`Y`, `M`, `W`, `D`, `H`, `M`, `S`); `S` for ms. */ readonly designator: "Y" | "M" | "W" | "D" | "H" | "S"; /** Whether the unit may carry a fraction (hour, minute, second only). */ readonly fraction: boolean; /** The symbol `formatHumanDuration` writes; empty for the millisecond, which is never written. */ readonly symbol: string; /** Every accepted spelling, lower case; matching is ASCII case-insensitive. */ readonly spellings: readonly string[]; } /** The single source of spellings for the reader and the writer. */ export declare const HUMAN_DURATION_UNITS: readonly HumanDurationUnit[]; /** * One `number unit` pair. Groups: 1 integer digits, 2 fraction digits (1 to 9), 3 unit spelling. * The spellings are built from `HUMAN_DURATION_UNITS` when the module loads; no ASCII letter may * follow the unit. Flags `i` and `y` only: no `u` or `v`, so the unit letters and the `[a-z]` * look-ahead stay ASCII-only (under `iu` they would match U+017F and U+212A) (G7). `\d` is ASCII * either way. * * Sticky and shared: every caller must set `lastIndex` before `exec` or `test`. */ export declare const HUMAN_DURATION_PAIR: RegExp; /** * Read a human duration string into an ISO 8601 duration string, before Temporal sees it. * Digits are kept as matched (no Number conversion); a fraction stays on its hour, minute or * second for Temporal to spread. Milliseconds fold into seconds with BigInt (G5). Returns `null` * for any string outside the grammar. The Temporal limits are not checked here. */ export declare function humanDurationToIso(text: string): string | null;