Skip to content

intervalsOverlap

intervalsOverlap(a: Interval, b: Interval): boolean

Return true when two half-open intervals share at least one instant.

  • a.start < b.end && b.start < a.end. Touching intervals (a.end is b.start) do not overlap: under [start, end) the shared endpoint belongs only to the later interval.
  • True exactly when intersectIntervals(a, b) is not null.
  • An empty interval (start === end) overlaps an interval it lies strictly inside, and nothing else — not at an edge, not another empty interval at the same instant (GMT rule: an empty interval covers no time, so only a strictly interior position is shared).
  • Compares instants: endpoints may name different zones.
  • The positional intervalsOverlapUtc, intervalsOverlapZoned, intervalsOverlapDate (…) follow the same half-open rule, so touching intervals do not overlap there either.
  • For zone-aligned windows (a local day, a trading session), build the endpoints with floorToZone first.
  • Returns false on invalid input — either interval not an Interval, or inverted.
ParameterTypeDescription
aInterval{ start, end } record of ISO 8601 instant strings
bInterval{ start, end } record of ISO 8601 instant strings

true if the intervals share an instant, or false on invalid input

import { intervalsOverlap } from "@northguild/gmt/interval/compare";
intervalsOverlap({ start: "2024-01-01T09:00:00Z", end: "2024-01-01T17:00:00Z" }, { start: "2024-01-01T12:00:00Z", end: "2024-01-01T18:00:00Z" }) // true
output 

interval/compare/intervalsOverlap.ts