intersectIntervals
Signature
Section titled “Signature”intersectIntervals(a: Interval, b: Interval): Interval | nullReturn 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 returnnull. - An empty interval strictly inside the other is returned as the intersection.
- Endpoints are the caller’s own strings, never re-serialised. When
aandbspell 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
nullon invalid input — either interval not anInterval, or inverted.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
a | Interval | { start, end } record of ISO 8601 instant strings; its strings win ties |
b | Interval | { start, end } record of ISO 8601 instant strings |
Returns
Section titled “Returns”{ start, end } of the shared span, or null when disjoint, touching, or on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”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" }