mergeIntervalsUtc
Signature
Section titled “Signature”mergeIntervalsUtc(intervals: { start: string; end: string; }[]): { start: string; end: string; }[]Collapse a list of UTC intervals into the minimum set of non-overlapping intervals.
- List-form generalization of
intervalUnionUtc, which is pairwise only. - Half-open: an interval holds every
twithstart <= t < end. Overlapping intervals and touching intervals (aEnd === bStart) join into one run; any gap, even one unit, keeps them apart (CORE-6’smergeIntervals). - An empty interval (
start === end) holds nothing: it is absorbed by a run it touches or lies in, and dropped otherwise, so every returned interval is non-empty. - Delegates to CORE-6’s
mergeIntervalsonce every element passes the UTC-string gate, and re-serialises the runs to canonicalZstrings. - 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 UTC datetime strings, or when any element hasstart > endor a leap-second string.
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
Members of each item
| Member | Type | Description |
|---|---|---|
start | string | The instant the interval begins at, as an ISO 8601 UTC string ending in Z. |
end | string | The first instant 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 is always later than start. |
Examples
Section titled “Examples”import { mergeIntervalsUtc } from "@northguild/gmt/utc/interval";
mergeIntervalsUtc([{ start: "2024-01-01T00:00:00Z", end: "2024-01-10T00:00:00Z" }, { start: "2024-01-05T00:00:00Z", end: "2024-01-15T00:00:00Z" }]) // [{ start: "2024-01-01T00:00:00Z", end: "2024-01-15T00:00:00Z" }]