mergeIntervalsDateTime
Signature
Section titled “Signature”mergeIntervalsDateTime(intervals: { start: string; end: string; }[]): { start: string; end: string; }[]import { mergeIntervalsDateTime } from "@northguild/gmt/plain/interval";Collapse a list of datetime intervals into the minimum set of non-overlapping intervals.
- List-form generalization of
intervalUnionDateTime, which is pairwise only. - Intervals are merged when they overlap or share an endpoint exactly (adjacent intervals ARE merged).
- Order of the input list does not matter; the result is sorted by start.
- Returns
[]for an empty list. - Returns
[]whenintervalsis not an array, when any element is not a{ start, end }record of valid ISO PlainDateTime strings, or when any element hasstart > end.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
intervals |
{ start: string; end: string; }[] |
array of { start, end } records |
Returns
Section titled “Returns”the minimum set of non-overlapping { start, end } records, sorted by start, or [] on invalid input
Examples
Section titled “Examples”mergeIntervalsDateTime([{ start: "2024-01-01T00:00:00", end: "2024-01-10T00:00:00" }, { start: "2024-01-05T00:00:00", end: "2024-01-15T00:00:00" }]) // [{ start: "2024-01-01T00:00:00", end: "2024-01-15T00:00:00" }]mergeIntervalsDateTime([]) // []mergeIntervalsDateTime([{ start: "2024-01-10T00:00:00", end: "2024-01-01T00:00:00" }]) // []