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.

66 lines • 3.79 kB
/** * The part of a Temporal ISO 8601 string before its first RFC 9557 annotation: everything before * the first `[`, or the whole string when it has none. * * GMT's validators check this part against GMT's strict ISO 8601 extended shape (`plainDate`, * `plainDateTime`, `plainTime`, `utcDateTime`, and `zonedDateTimeBody` / `instantBody` below) and hand the whole string to `Temporal.X.from`, which applies Temporal's * annotation grammar (proposal-temporal `ParseISODateTime`; RFC 9557 §3.3): elective unknown * annotations and a time zone annotation on a plain value are read and ignored, the first `u-ca` * annotation names the calendar, and an unknown critical annotation is rejected. The same split * as `internal/calendarDateString.ts`. * * @param value candidate ISO 8601 string * @returns the string up to its first annotation, or `""` for a non-string * * @example isoStringBody("2024-03-10[u-ca=iso8601]") // "2024-03-10" * @example isoStringBody("2024-03-10T12:30Z[foo=bar]") // "2024-03-10T12:30Z" * @example isoStringBody("12:30") // "12:30" */ export declare function isoStringBody(value: string): string; /** * An ISO 8601 extended UTC offset, as RFC 3339 §5.6 `time-numoffset` writes it (`±HH:MM`), with * the seconds and fraction Temporal's `UTCOffset` grammar adds (`±HH:MM:SS[.fraction]`, the * fraction after either decimal sign, `.` or `,`, as `TemporalDecimalSeparator` allows). Hours * 00–23. Basic (`-0400`) and hour-only (`-04`) offsets, which Temporal also reads, do not match. * * A regular-expression source with no anchors and no capture groups, so callers can embed it: * GMT's one statement of the offset grammar its instant and zoned validators accept. * * @example new RegExp(`^${EXTENDED_UTC_OFFSET}$`).test("+05:30:00,5") // true * @example new RegExp(`^${EXTENDED_UTC_OFFSET}$`).test("-0400") // false (basic format) */ export declare const EXTENDED_UTC_OFFSET = "[+-](?:[01]\\d|2[0-3]):[0-5]\\d(?::[0-5]\\d(?:[.,]\\d{1,9})?)?"; /** * An RFC 9557 time-zone annotation: a bracket whose content has no `=` (§4.1 `time-zone`, * against `suffix-tag`'s `key=value`), with an optional leading `!` marking it critical (§3.3). * `[Europe/London]`, `[!+01:00]`; never `[u-ca=hebrew]` or `[!foo=bar]`. Every `key=value` * bracket is a tagged annotation, which Temporal reads (or rejects) on its own. * * A regular-expression source with no anchors and no capture groups, so callers can embed or * anchor it: GMT's one statement of "this bracket names a time zone". * * @example new RegExp(TIME_ZONE_ANNOTATION).test("2024-06-15T10:00:00Z[!Europe/London]") // true * @example new RegExp(TIME_ZONE_ANNOTATION).test("2024-06-15T10:00:00Z[u-ca=gregory]") // false */ export declare const TIME_ZONE_ANNOTATION = "\\[!?[^\\]=]+\\]"; /** * True when `value` is a string whose part before the first annotation is `zonedDateTimeBody`. * The shape gate every GMT zoned string input passes before `Temporal.ZonedDateTime.from`. * * @param value candidate zoned datetime string * @returns whether the unannotated part has GMT's strict extended zoned shape * * @example hasZonedDateTimeShape("2024-10-03T14:30:00+05:30[Asia/Kolkata]") // true * @example hasZonedDateTimeShape("2024-10-03 14:30:00+05:30[Asia/Kolkata]") // false */ export declare function hasZonedDateTimeShape(value: string): boolean; /** * True when `value` is a string whose part before the first annotation is `instantBody`. * * @param value candidate instant string * @returns whether the unannotated part has GMT's strict extended instant shape * * @example hasInstantShape("2024-10-03T18:30:00Z[foo=bar]") // true * @example hasInstantShape("20241003T183000Z") // false */ export declare function hasInstantShape(value: string): boolean;