Skip to content

intervalSplitAtUnix

intervalSplitAtUnix(start: string | number, end: string | number, points: (string | number)[]): { start: number; end: number; }[]

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

  • points need not be sorted — they are sorted internally before splitting.
  • Points before start or after 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 consecutive half-open [start, end) records, the same tiling as splitIntervalAt: each record’s end is the next record’s start and belongs only to that next record, so the pieces share no value and together cover [start, end) exactly once.
  • Returns [{ start, end }] (the whole interval, unsplit) when no valid in-range point remains.
  • A piece’s end equals its start only when the interval itself is zero-length (start equal to end): the result is then that one empty piece, whatever the points.
  • Returns [] when points is not an array, or when start, end or any point is not a safe integer (or numeric string of one) — fractions, empty strings and values beyond ±(2^53 − 1) are invalid even when they would fall outside the interval — or when start > end.
ParameterTypeDescription
startstring | numberUnix epoch value, in the one unit all epoch arguments share — interval start
endstring | numberUnix epoch value, in the one unit all epoch arguments share — interval end
points(string | number)[]array of Unix epoch values to split at

array of { start, end } records, 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 can equal start, which makes the interval empty.
import { intervalSplitAtUnix } from "@northguild/gmt/unix/interval";
intervalSplitAtUnix(0, 100000, [50000]) // [{ start: 0, end: 50000 }, { start: 50000, end: 100000 }]
points
output 

unix/interval/intervalSplitAtUnix.ts