isValidZonedDateTime
Signature
Section titled “Signature”isValidZonedDateTime(value: string): booleanValidate whether a string is a valid ISO 8601 zoned datetime string.
- The part before the first annotation must be ISO 8601 extended format:
<date>T<time>, then nothing,Z, or a±HH:MM[:SS[.fraction]]offset. Basic format (20241003T143000-0400), a space or lower-casetseparator, a lower-casez, an hour-only time or offset, and a date without a time are rejected, althoughTemporal.ZonedDateTime.fromreads them. - Uses Temporal.ZonedDateTime.from for validation.
- A written offset must agree with the bracketed zone, as TC39
ToTemporalZonedDateTimematches it: an offset written to the minute may be the zone’s sub-minute offset rounded (-00:45[Africa/Monrovia]for −00:44:30, which is how Temporal writes it), and an offset written with seconds must be the zone’s offset exactly. - Rejects leap seconds.
- With an offset, the local date must be inside Temporal’s date range, as
Temporal.ZonedDateTime.fromrequires (CheckISODaysRange): a zoned string on −271821-04-19, which a zone west of Greenwich shows for the first hours of the instant range, is rejected althoughisValidInstantaccepts it. - Reads RFC 9557 annotations as
Temporal.ZonedDateTime.fromdoes: elective ones ([foo=bar]) are ignored and an unknown critical one ([!foo=bar]) is rejected. - The calendar must be ISO:
[u-ca=iso8601]is accepted, and a non-ISO calendar annotation isisValidCalendarZonedDateTime’s input. - Returns false for non-strings or empty strings.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | candidate zoned datetime string |
Returns
Section titled “Returns”boolean indicating validity
Examples
Section titled “Examples”import { isValidZonedDateTime } from "@northguild/gmt/zoned/validate";
isValidZonedDateTime("2024-02-29T12:34:56.789+00:00[UTC]") // true