Skip to content

intervalsOverlapZoned

intervalsOverlapZoned(aStart: string, aEnd: string, bStart: string, bEnd: string): boolean
import { intervalsOverlapZoned } from "@northguild/gmt/zoned/interval";

Return true when intervals [aStart, aEnd] and [bStart, bEnd] share at least one instant.

  • Uses Temporal.Instant.compare for comparison (same instant semantics).
  • Adjacent intervals (e.g. aEnd === bStart) do NOT overlap — returns false.
  • Returns false if either interval is invalid (start > end).
  • Returns false on invalid input (wrong type, malformed strings, leap seconds).
  • Accepts mixed calendar systems (E7’s D4-zoned, issue #152): both bare ISO zoned strings and GMT calendar-annotated ones ("5784-06-15T14:30:00-05:00[u-ca=hebrew][America/New_York]"), and the two endpoints need not agree on a calendar. Ordering is calendar-independent — verified that Temporal.Instant carries no calendar field at all and that Instant.compare/ZonedDateTime.compare both return 0 for the same instant expressed in hebrew, islamic-civil, japanese and iso8601.
  • Still rejects Temporal’s own [timeZone][u-ca=...] RFC 9557 ordering, which reads GMT’s calendar-native digits as ISO digits — see regex/calendar-zoned-date-time.ts.
Parameter Type Description
aStart string ISO 8601 zoned datetime string for the first interval start
aEnd string ISO 8601 zoned datetime string for the first interval end
bStart string ISO 8601 zoned datetime string for the second interval start
bEnd string ISO 8601 zoned datetime string for the second interval end

true if intervals overlap, or false on invalid input

intervalsOverlapZoned("2024-01-01T00:00:00+00:00[UTC]", "2024-06-30T23:59:59+00:00[UTC]", "2024-04-01T00:00:00+00:00[UTC]", "2024-12-31T23:59:59+00:00[UTC]") // true
intervalsOverlapZoned("2024-01-01T00:00:00+00:00[UTC]", "2024-06-30T23:59:59+00:00[UTC]", "2024-07-01T00:00:00+00:00[UTC]", "2024-12-31T23:59:59+00:00[UTC]") // false (adjacent)
intervalsOverlapZoned("invalid", "2024-06-30T23:59:59+00:00[UTC]", "2024-04-01T00:00:00+00:00[UTC]", "2024-12-31T23:59:59+00:00[UTC]") // false

zoned/interval/intervalsOverlapZoned.ts