mergeIntervalsUnix
Signature
Section titled “Signature”mergeIntervalsUnix(intervals: { start: string | number; end: string | number; }[]): { start: number; end: number; }[]Collapse a list of Unix epoch intervals into the minimum set of non-overlapping intervals.
- List-form generalization of
intervalUnionUnix, which is pairwise only. - Intervals are half-open
[start, end), the same rule asmergeIntervals. They are merged when they overlap or touch (one’sendequals the other’sstart), so the runs returned never touch. - An empty interval (
start === end) holds no instant: it is absorbed when it touches or lies inside a run and dropped otherwise, so it never bridges a gap. A list of only empty intervals returns[], the same value as invalid input — useisValidUnixIntervalto tell them apart. - 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 safe-integer (or numeric-string) values — fractions, empty strings and values beyond ±(2^53 − 1) are invalid — or when any element hasstart > end.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
intervals | { start: string | number; end: string | number; }[] | 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 | number | The instant the interval begins at, as a Unix epoch number in the unit the arguments share. |
end | number | The first instant after the interval, in the same unit 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 { mergeIntervalsUnix } from "@northguild/gmt/unix/interval";
mergeIntervalsUnix([{ start: 0, end: 1000000 }, { start: 500000, end: 1500000 }]) // [{ start: 0, end: 1500000 }]