Skip to content

intersectIntervals

intersectIntervals(a: Interval, b: Interval): Interval | null

Return the half-open interval two intervals share, or null when they share no instant.

  • Non-null exactly when intervalsOverlap(a, b) is true: touching intervals return null.
  • An empty interval strictly inside the other is returned as the intersection.
  • Endpoints are the caller’s own strings, never re-serialised. When a and b spell the same instant differently, a’s spelling is used (GMT rule: the first argument wins ties).
  • The positional intervalIntersectionUtc (…) follow the same half-open rule and return re-serialised endpoints instead of echoing the caller’s strings.
  • Returns null on invalid input — either interval not an Interval, or inverted.
ParameterTypeDescription
aInterval{ start, end } record of ISO 8601 instant strings; its strings win ties
bInterval{ start, end } record of ISO 8601 instant strings

{ start, end } of the shared span, or null when disjoint, touching, or on invalid input

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

interval/calculate/intersectIntervals.ts