intervalXorAllUtc
Signature
Section titled “Signature”intervalXorAllUtc(intervals: { start: string; end: string; }[]): { start: string; end: string; }[]import { intervalXorAllUtc } from "@northguild/gmt/utc/interval";Return the symmetric difference across a list of UTC intervals — the set of instants covered
- by an odd number of the input intervals.
- List-form generalization of
intervalXorUtc, which is pairwise only. - Implemented as a coverage sweep: each interval contributes a
+1at its start and a-1one nanosecond after its end; the result is every maximal run where the running coverage count is odd. For two intervals this reduces to exactlyintervalXorUtc’s pairwise result. - Order of the input list does not matter; the result is sorted by start.
- Returns
[]for an empty list, and[]when every instant is covered an even number of times (e.g. two identical intervals cancel out). - Returns
[]whenintervalsis not an array, when any element is not a{ start, end }record of valid ISO UTC datetime strings, or when any element hasstart > endor a leap-second string.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
intervals |
{ start: string; end: string; }[] |
array of { start, end } records |
Returns
Section titled “Returns”array of { start, end } records covered an odd number of times, or [] on invalid input
Examples
Section titled “Examples”intervalXorAllUtc([{ start: "2024-01-01T00:00:00Z", end: "2024-01-10T00:00:00Z" }, { start: "2024-01-05T00:00:00Z", end: "2024-01-15T00:00:00Z" }]) // [{ start: "2024-01-01T00:00:00Z", end: "2024-01-04T23:59:59.999999999Z" }, { start: "2024-01-10T00:00:00.000000001Z", end: "2024-01-15T00:00:00Z" }]intervalXorAllUtc([]) // []