Skip to content

intervalXorUnix

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 mergeIntervals of subtractIntervals(a, [b]) and subtractIntervals(b, [a]), and the same as intervalXorAllUnix([a, b]).
  • Every boundary is an input’s own start or end; 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)).
ParameterTypeDescription
aStartstring | numberUnix epoch value, in the one unit all epoch arguments share — first interval start
aEndstring | numberUnix epoch value, in the one unit all epoch arguments share — first interval end
bStartstring | numberUnix epoch value, in the one unit all epoch arguments share — second interval start
bEndstring | numberUnix epoch value, in the one unit all epoch arguments share — second interval end

array of { start, end } records representing the symmetric difference, or [] on invalid input

Members of each item

MemberTypeDescription
startnumberThe instant the interval begins at, as a Unix epoch number in the unit the arguments share.
endnumberThe 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.
import { intervalXorUnix } from "@northguild/gmt/unix/interval";
intervalXorUnix(0, 1500000000, 1400000000, 1700000000) // [{ start: 0, end: 1400000000 }, { start: 1500000000, end: 1700000000 }]
output 

unix/interval/intervalXorUnix.ts