Skip to content

intervalXorUnix

intervalXorUnix(aStart: string | number, aEnd: string | number, bStart: string | number, bEnd: string | number): { start: number; end: number; }[]
import { intervalXorUnix } from "@northguild/gmt/unix/interval";

Return the symmetric difference of two Unix intervals — time covered by exactly one interval.

  • Compares numeric Unix epoch values directly.
  • Returns [] when intervals are identical or both invalid.
  • Returns [{ start, end }] when one interval fully contains the other.
  • Returns [{ start, end }, { start, end }] when intervals partially overlap.
  • Returns [] if either interval is invalid (start > end).
  • Returns [] on invalid input (non-numeric types, non-finite values).
Parameter Type Description
aStart string | number Unix epoch value (seconds or milliseconds) — first interval start
aEnd string | number Unix epoch value (seconds or milliseconds) — first interval end
bStart string | number Unix epoch value (seconds or milliseconds) — second interval start
bEnd string | number Unix epoch value (seconds or milliseconds) — second interval end

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

intervalXorUnix(0, 1500000000, 1400000000, 1700000000) // [{ start: 0, end: 1399999999 }, { start: 1500000001, end: 1700000000 }]
intervalXorUnix(0, 1700000000, 1400000000, 1500000000) // [{ start: 0, end: 1399999999 }, { start: 1500000001, end: 1700000000 }]
intervalXorUnix(0, 1700000000, 0, 1700000000) // []
intervalXorUnix(NaN, 1500000000, 1400000000, 1700000000) // []

unix/interval/intervalXorUnix.ts