@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
26 lines (25 loc) • 1.12 kB
TypeScript
/**
* 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 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 `[]` when `intervals` is not an array, when any element is not a
* `{ start, end }` record of finite numeric (or numeric-string) values, or when any element
* has `start > end`.
*
* @param intervals array of `{ start, end }` records
* @returns the minimum set of non-overlapping `{ start, end }` records, sorted by start, or `[]` on invalid input
*
* @example mergeIntervalsUnix([{ start: 0, end: 1000000 }, { start: 500000, end: 1500000 }]) // [{ start: 0, end: 1500000 }]
* @example mergeIntervalsUnix([]) // []
*/
export declare function mergeIntervalsUnix(intervals: Array<{
start: number | string;
end: number | string;
}>): Array<{
start: number;
end: number;
}>;