intervalSplitAtDateTime
Signature
Section titled “Signature”intervalSplitAtDateTime(start: string, end: string, points: string[]): { start: string; end: string; }[]import { intervalSplitAtDateTime } from "@northguild/gmt/plain/interval";Split a datetime 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, whichdivideEqually’s zero-length case is the deliberate way to express, notsplitAt’s. - 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 valid ISO PlainDateTime string, or on invalid input (unparseable start/end,start > end).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start |
string |
ISO PlainDateTime string for the interval start |
end |
string |
ISO PlainDateTime string for the interval end |
points |
string[] |
array of ISO PlainDateTime strings to split at |
Returns
Section titled “Returns”array of { start, end } records, or [] on invalid input
Examples
Section titled “Examples”intervalSplitAtDateTime("2024-01-01T00:00:00", "2024-01-10T00:00:00", ["2024-01-05T00:00:00"]) // [{ start: "2024-01-01T00:00:00", end: "2024-01-05T00:00:00" }, { start: "2024-01-05T00:00:00", end: "2024-01-10T00:00:00" }]intervalSplitAtDateTime("2024-01-01T00:00:00", "2024-01-10T00:00:00", []) // [{ start: "2024-01-01T00:00:00", end: "2024-01-10T00:00:00" }]intervalSplitAtDateTime("invalid", "2024-01-10T00:00:00", ["2024-01-05T00:00:00"]) // []intervalSplitAtDateTime("2024-01-01T00:00:00", "2024-01-10T00:00:00", ["not-a-datetime"]) // []