intervalSplitAtUnix
Signature
Section titled “Signature”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.
pointsneed not be sorted — they are sorted internally before splitting.- Points before
startor afterendare 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 consecutive half-open
[start, end)records, the same tiling assplitIntervalAt: each record’sendis the next record’sstartand 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
endequals itsstartonly when the interval itself is zero-length (startequal toend): the result is then that one empty piece, whatever the points. - Returns
[]whenpointsis not an array, or whenstart,endor 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 whenstart > end.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start | string | number | Unix epoch value, in the one unit all epoch arguments share — interval start |
end | string | number | Unix epoch value, in the one unit all epoch arguments share — 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
Members of each item
| Member | Type | Description |
|---|---|---|
start | number | The instant the interval begins at, as a Unix epoch number in the unit the arguments share. |
end | number | The 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. |
Examples
Section titled “Examples”import { intervalSplitAtUnix } from "@northguild/gmt/unix/interval";
intervalSplitAtUnix(0, 100000, [50000]) // [{ start: 0, end: 50000 }, { start: 50000, end: 100000 }]