intervalSplitAtTime
Signature
Section titled “Signature”intervalSplitAtTime(start: string, end: string, points: string[]): { start: string; end: string; }[]Split a time 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;intervalDivideEquallyTime’s zero-length case is the deliberate way to express one, notintervalSplitAtTime. - Duplicate points collapse to a single boundary.
- Returns consecutive
{ start, end }records, each record’sendequal to the next record’sstart. - Every piece is half-open
[start, end): a boundary belongs only to the piece that starts there, so the pieces share no value and together cover the interval exactly once (the rule CORE-6’ssplitIntervalAtuses). - 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, when any element is not a valid ISO PlainTime string, or on invalid input (unparseable start/end,start > end).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start | string | ISO PlainTime string for the interval start |
end | string | ISO PlainTime string for the interval end |
points | string[] | array of ISO PlainTime strings to split at |
Returns
Section titled “Returns”array of { start, end } records, or [] on invalid input
Members of each item
| Member | Type | Description |
|---|---|---|
start | string | The clock time the interval begins at, as an ISO 8601 time string with no date, offset or time zone. |
end | string | The first clock time after the interval, in the same format 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 { intervalSplitAtTime } from "@northguild/gmt/plain/interval";
intervalSplitAtTime("09:00:00", "17:00:00", ["12:00:00"]) // [{ start: "09:00:00", end: "12:00:00" }, { start: "12:00:00", end: "17:00:00" }]