isValidCalendarZonedDateTime
Signature
Section titled “Signature”isValidCalendarZonedDateTime(value: string): booleanReturn true if value is a valid GMT ZonedDateTime string: a bare ISO zoned datetime (“2024-10-03T14:30:45-04:00[America/New_York]”) or an RFC 9557 calendar-annotated one (“2024-10-03T14:30:45-04:00[America/New_York][u-ca=hebrew]”), as Temporal.ZonedDateTime#toString() and convertZonedToCalendar write it.
- Parallel to
isValidZonedDateTime, which accepts[u-ca=iso8601]and rejects every other calendar. Only the calendar-awarezoned/functions gate on this validator, so a string is never certified by a validator whose own namespace refuses it. - The calendar annotation follows the time zone annotation (RFC 9557 §4.1); a calendar before the zone, which Temporal also rejects, returns false.
- A
[u-ca=<id>]annotation, optionally critical. Temporal’sCanonicalizeCalendarvalidates the id (folding case and aliases), and the calendar must be one GMT supports (CalendarSystem). - The annotations follow Temporal’s ISO grammar, as
Temporal.ZonedDateTime.fromreads them: elective unknown annotations ([foo=bar]) are ignored and the firstu-caannotation names the calendar; an unknown critical annotation or a secondu-caannotation when either is critical returns false. - The part before the first annotation must be ISO 8601 extended format, as
isValidZonedDateTimerequires: basic format, a space or lower-casetseparator, a lower-casez, an hour-only time or offset and a date without a time return false. - Rejects leap seconds, which
Temporal.ZonedDateTime.fromotherwise clamps to:59. - Delegates the date, time, offset, zone and annotation checks to
Temporal.ZonedDateTime.from(viaparseCalendarZonedValue). - Returns false for non-strings or empty strings. Compatibility: since 1.16.0 the string is RFC 9557. Earlier releases accepted calendar-native digits,
;era=, the calendar annotation before the zone, and the idsgregorian,taiwan,islamic-tabularandethiopic-amete-alem.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | candidate zoned datetime string, optionally calendar-annotated |
Returns
Section titled “Returns”boolean indicating validity
Examples
Section titled “Examples”import { isValidCalendarZonedDateTime } from "@northguild/gmt/zoned/validate";
isValidCalendarZonedDateTime("2024-10-03T14:30:45-04:00[America/New_York]") // true