Skip to content

intervalDifferenceUnix

intervalDifferenceUnix(aStart: string | number, aEnd: string | number, bStart: string | number, bEnd: string | number): { start: number; end: number; }[]

Return the portion(s) of the half-open interval A [aStart, aEnd) not covered by the half-open interval B [bStart, bEnd).

  • Compares numeric Unix epoch values directly, with the same rule as subtractIntervals.
  • Every cut lands exactly on B’s own start or end: the piece before B ends at bStart, which it excludes, and the piece after B starts at bEnd, which B excludes. No boundary is stepped by an epoch unit.
  • Returns [] when B fully covers A, and when A is empty (aStart === aEnd).
  • Returns [{ start, end }] when B overlaps one edge of A.
  • Returns [{ start, end }, { start, end }] when B is fully inside A with gaps on both sides.
  • Returns A unchanged when B lies entirely before or after it, touches it, or is empty.
  • 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 A minus B, 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 { intervalDifferenceUnix } from "@northguild/gmt/unix/interval";
intervalDifferenceUnix(0, 1700000000, 1500000000, 1600000000) // [{ start: 0, end: 1500000000 }, { start: 1600000000, end: 1700000000 }]
output 

unix/interval/intervalDifferenceUnix.ts