Skip to content

intervalIntersectionUnix

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

Return the overlapping span of two Unix epoch intervals, or null when they do not overlap.

  • Compares numeric Unix epoch values directly.
  • Adjacent intervals (e.g. aEnd === bStart) share one instant and DO overlap.
  • Returns null if either interval is invalid (start > end).
  • Returns null 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

{ start, end } with the overlapping span, or null on invalid input / no overlap

intervalIntersectionUnix(0, 1700000000, 1000000, 2000000) // { start: 1000000, end: 1700000000 }
intervalIntersectionUnix(0, 1000000, 1000000, 2000000) // { start: 1000000, end: 1000000 }
intervalIntersectionUnix(0, 1000000, 1000001, 2000000) // null
intervalIntersectionUnix(NaN, 1700000000, 1000000, 2000000) // null
intervalIntersectionUnix("0", "1700000000", "1000000", "2000000") // { start: 1000000, end: 1700000000 }

unix/interval/intervalIntersectionUnix.ts