Skip to content

intervalSplitAtUnix

intervalSplitAtUnix(start: string | number, end: string | number, points: (string | number)[]): { start: number; end: number; }[]
import { intervalSplitAtUnix } from "@northguild/gmt/unix/interval";

Split a Unix epoch interval at arbitrary points, producing consecutive sub-intervals.

  • points need not be sorted — they are sorted internally before splitting.
  • Points outside [start, end] are dropped; they cannot introduce a boundary that isn’t inside the interval.
  • Points exactly on start or end are dropped too — they would only produce a zero-length sub-interval at the edge.
  • Duplicate points collapse to a single boundary.
  • Returns [{ start, end }] (the whole interval, unsplit) when no valid in-range point remains.
  • Returns [] when points is not an array, when any element is not a finite number (or numeric string), or on invalid input (non-finite/non-integer start/end, start > end).
Parameter Type Description
start string | number Unix epoch value (seconds or milliseconds) — interval start
end string | number Unix epoch value (seconds or milliseconds) — interval end
points (string | number)[] array of Unix epoch values to split at

array of { start, end } records, or [] on invalid input

intervalSplitAtUnix(0, 100000, [50000]) // [{ start: 0, end: 50000 }, { start: 50000, end: 100000 }]
intervalSplitAtUnix(0, 100000, []) // [{ start: 0, end: 100000 }]
intervalSplitAtUnix(NaN, 100000, [50000]) // []

unix/interval/intervalSplitAtUnix.ts