Skip to content

isValidCalendarZonedInterval

isValidCalendarZonedInterval(start: string, end: string): boolean
import { isValidCalendarZonedInterval } from "@northguild/gmt/zoned/interval";

Return true if start and end form a valid GMT zoned interval — both parseable as bare ISO

  • or GMT calendar-annotated ZonedDateTime strings, and the instant at start is <= the instant at end.
  • Parallel to isValidZonedInterval, which is deliberately left unchanged and still rejects every [u-ca=...] annotation (E7, issue #152). Only the calendar-aware zoned/interval/* functions gate on this one.
  • Mixed calendars are accepted (E7’s D4-zoned, matching E5’s D4): ordering is calendar-independent. Verified against @js-temporal/polyfill@0.5.1Temporal.Instant carries no calendar field at all, and ZonedDateTime.compare / Instant.compare both return 0 for the same instant expressed in hebrew, islamic-civil, japanese and iso8601. A Hebrew start with an Islamic end is a well-formed interval.
  • Equal start === end is valid.
  • Comparison is done by instant, so intervals spanning DST transitions are compared by absolute time.
  • Rejects Temporal’s [timeZone][u-ca=...] ordering, leap seconds, non-strings, and any unparseable endpoint.
Parameter Type Description
start string ISO or GMT calendar-annotated ZonedDateTime string (interval start)
end string ISO or GMT calendar-annotated ZonedDateTime string (interval end)

true if start and end form a valid zoned interval, or false on invalid input

isValidCalendarZonedInterval("2024-01-01T10:00:00+00:00[UTC]", "2024-12-31T23:59:59+00:00[UTC]") // true
isValidCalendarZonedInterval("5784-06-15T14:30:00-05:00[u-ca=hebrew][America/New_York]", "5784-07-15T14:30:00-04:00[u-ca=hebrew][America/New_York]") // true
isValidCalendarZonedInterval("5784-06-15T14:30:00-05:00[u-ca=hebrew][America/New_York]", "1445-09-15T14:30:00-04:00[u-ca=islamic-civil][America/New_York]") // true (mixed calendars accepted)
isValidCalendarZonedInterval("2024-12-31T23:59:59+00:00[UTC]", "2024-01-01T10:00:00+00:00[UTC]") // false (start after end)
isValidCalendarZonedInterval("2024-01-01T10:00:00+00:00[UTC][u-ca=hebrew]", "2024-12-31T23:59:59+00:00[UTC]") // false (Temporal's segment ordering)
isValidCalendarZonedInterval("invalid", "2024-12-31T23:59:59+00:00[UTC]") // false

zoned/interval/validate/isValidCalendarZonedInterval.ts