@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.
30 lines • 1.95 kB
TypeScript
/**
* RegExp matching a calendar-annotated ZonedDateTime string in the RFC 9557 form Temporal writes
* and reads — the zoned sibling of `calendarDate` (regex/calendar-date.ts):
*
* <date>T<time><offset>[<timeZone>][u-ca=<id>]
* 2024-02-24T14:30:00+02:00[Asia/Jerusalem][u-ca=hebrew]
*
* This is exactly `Temporal.ZonedDateTime#toString()` for a non-ISO calendar. The digits are ISO
* and the calendar annotation follows the time zone annotation, in RFC 9557 §4.1 order. The date,
* time and offset are ISO 8601 extended format with an upper-case `Z`. The date
* half and the annotation are the same groups as `calendarDate`'s. The offset is optional; the
* time zone annotation may carry RFC 9557's critical flag (`[!Asia/Jerusalem]`), and so may the
* calendar annotation.
*
* A match proves shape only: `internal/calendarZonedString.ts` hands the string to
* `Temporal.ZonedDateTime.from` (zone, offset, DST) and the calendar id to Temporal's
* `CanonicalizeCalendar`. This is the written form. GMT's calendar functions read more
* (`isValidCalendarZonedDateTime`): every date-time `isValidZonedDateTime` reads (the functions
* take the same strings as the non-calendar zoned functions, then the calendar annotation), and
* the rest of Temporal's annotation grammar, such as an elective `[foo=bar]`, which Temporal
* ignores.
*
* Capture groups: 1 year, 2 month, 3 day, 4 time, 5 offset (optional), 6 time zone annotation
* (with its critical flag, if any), 7 calendar critical flag (`"!"` or undefined), 8 calendar id.
*
* @example calendarZonedDateTime.test("2024-02-24T14:30:00+02:00[Asia/Jerusalem][u-ca=hebrew]") // true
* @example calendarZonedDateTime.test("2024-02-24T14:30:00+02:00[u-ca=hebrew][Asia/Jerusalem]") // false (calendar before zone)
* @example calendarZonedDateTime.test("2024-03-15T14:30:00Z[UTC]") // false (no calendar annotation)
*/
export declare const calendarZonedDateTime: RegExp;