splitIntervalAt
Signature
Section titled “Signature”splitIntervalAt(interval: Interval, boundaries: string[]): Interval[]Split a half-open interval at instant boundaries into consecutive half-open pieces.
- Each piece’s
endis the next piece’sstart; under[start, end)the pieces share no instant and together cover the interval exactly once. boundariesmay be unsorted. Boundaries at or outside the interval’s edges are dropped, so no piece is empty; duplicate instants keep their first occurrence’s spelling (GMT rule).- Endpoints are the caller’s own strings: the interval’s own
start/end, and each boundary exactly as passed. - Splitting an empty interval returns it unchanged, as a single piece.
- Never returns
[]for valid input — that is the invalid-input sentinel alone. - To split at zone-aligned boundaries (local midnights), build them with
floorToZoneorbucketRangefirst. - Returns
[]whenintervalis not a validInterval,boundariesis not an array, or any boundary is not an ISO 8601 instant string — even one outside the interval.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
interval | Interval | { start, end } record of ISO 8601 instant strings to split |
boundaries | string[] | array of ISO 8601 instant strings to split at |
Returns
Section titled “Returns”consecutive { start, end } pieces covering interval, or [] on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { splitIntervalAt } from "@northguild/gmt/interval/calculate";
splitIntervalAt({ start: "2024-01-01T09:00:00Z", end: "2024-01-01T17:00:00Z" }, ["2024-01-01T12:00:00Z"]) // [{ start: "2024-01-01T09:00:00Z", end: "2024-01-01T12:00:00Z" }, { start: "2024-01-01T12:00:00Z", end: "2024-01-01T17:00:00Z" }]