Skip to content

isValidZonedDateTime

isValidZonedDateTime(value: string): boolean
import { isValidZonedDateTime } from "@northguild/gmt/zoned/validate";

Validate whether a string is a valid ISO 8601 zoned datetime string.

  • Uses Temporal.ZonedDateTime.from for validation.
  • Rejects leap seconds.
  • Rejects any [u-ca=...] calendar annotation (E5 issue #78, decision of record D2): calendar-system awareness is confined to plain/ PlainDate values (D1) — zoned/ previously accepted the annotation by accident (nothing gated it) and did genuinely calendar-aware but undocumented, untested arithmetic; this closes that rather than blessing it. See context/roadmap/issues/E.md’s E5 section for the follow-up story proposal to extend zoned/ with a GMT-shape annotated string deliberately.
  • Returns false for non-strings or empty strings.
Parameter Type Description
value string candidate zoned datetime string

boolean indicating validity

isValidZonedDateTime("2024-02-29T12:34:56.789+00:00[UTC]") // true
isValidZonedDateTime("2024-06-30T23:59:60+00:00[UTC]") // false (leap second)
isValidZonedDateTime("2024-02-10T12:00:00-05:00[America/New_York][u-ca=hebrew]") // false (calendar annotation rejected)
isValidZonedDateTime("invalid") // false

zoned/validate/isValidZonedDateTime.ts