intervalSplitAtUtc
Signature
Section titled “Signature”intervalSplitAtUtc(start: string, end: string, points: string[]): { start: string; end: string; }[]import { intervalSplitAtUtc } from "@northguild/gmt/utc/interval";Split a UTC 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 valid ISO UTC datetime string, or on invalid input (unparseable start/end,start > end, leap-second strings).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start |
string |
ISO UTC datetime string for the interval start |
end |
string |
ISO UTC datetime string for the interval end |
points |
string[] |
array of ISO UTC datetime strings to split at |
Returns
Section titled “Returns”array of { start, end } records, or [] on invalid input
Examples
Section titled “Examples”intervalSplitAtUtc("2024-01-01T00:00:00Z", "2024-01-10T00:00:00Z", ["2024-01-05T00:00:00Z"]) // [{ start: "2024-01-01T00:00:00Z", end: "2024-01-05T00:00:00Z" }, { start: "2024-01-05T00:00:00Z", end: "2024-01-10T00:00:00Z" }]intervalSplitAtUtc("2024-01-01T00:00:00Z", "2024-01-10T00:00:00Z", []) // [{ start: "2024-01-01T00:00:00Z", end: "2024-01-10T00:00:00Z" }]intervalSplitAtUtc("invalid", "2024-01-10T00:00:00Z", ["2024-01-05T00:00:00Z"]) // []