intervalXorUnix
Signature
Section titled “Signature”intervalXorUnix(aStart: string | number, aEnd: string | number, bStart: string | number, bEnd: string | number): { start: number; end: number; }[]Return the symmetric difference of two half-open Unix intervals [start, end) — the values covered by exactly one interval.
- Compares numeric Unix epoch values directly.
- The result is every maximal run covered by exactly one interval, sorted by start — the same as
mergeIntervalsofsubtractIntervals(a, [b])andsubtractIntervals(b, [a]), and the same asintervalXorAllUnix([a, b]). - Every boundary is an input’s own
startorend; no boundary is stepped by an epoch unit. - Touching intervals share no value, so they join into one run (
[0, 5)xor[5, 10)is[0, 10)). An empty interval (start === end) holds no value and changes nothing. - Returns
[]when the intervals are identical. - Returns
[{ start, end }]when the intervals share a start or an end, or touch. - Returns
[{ start, end }, { start, end }]when they partially overlap, when one strictly contains the other, or when they are disjoint with a gap. - Returns
[]if either interval is invalid (start > end). - Returns
[]on invalid input: non-numeric types, empty strings, and values that are not safe integers (fractions,NaN,±Infinity, beyond ±(2^53 − 1)).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
aStart | string | number | Unix epoch value, in the one unit all epoch arguments share — first interval start |
aEnd | string | number | Unix epoch value, in the one unit all epoch arguments share — first interval end |
bStart | string | number | Unix epoch value, in the one unit all epoch arguments share — second interval start |
bEnd | string | number | Unix epoch value, in the one unit all epoch arguments share — second interval end |
Returns
Section titled “Returns”array of { start, end } records representing the symmetric difference, or [] on invalid input
Members of each item
| Member | Type | Description |
|---|---|---|
start | number | The instant the interval begins at, as a Unix epoch number in the unit the arguments share. |
end | number | The first instant after the interval, in the same unit as start. It is exclusive: the interval holds everything from start up to but not including this value. It is always later than start. |
Examples
Section titled “Examples”import { intervalXorUnix } from "@northguild/gmt/unix/interval";
intervalXorUnix(0, 1500000000, 1400000000, 1700000000) // [{ start: 0, end: 1400000000 }, { start: 1500000000, end: 1700000000 }]