intervalSplitAtUnix
Signature
Section titled “Signature”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.
pointsneed 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
startorendare 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
[]whenpointsis 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).
Parameters
Section titled “Parameters”| 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 |
Returns
Section titled “Returns”array of { start, end } records, or [] on invalid input
Examples
Section titled “Examples”intervalSplitAtUnix(0, 100000, [50000]) // [{ start: 0, end: 50000 }, { start: 50000, end: 100000 }]intervalSplitAtUnix(0, 100000, []) // [{ start: 0, end: 100000 }]intervalSplitAtUnix(NaN, 100000, [50000]) // []