@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
27 lines (26 loc) • 1.19 kB
TypeScript
/**
* Collapse a list of time intervals into the minimum set of non-overlapping intervals.
*
* - List-form generalization of `intervalUnionTime`, 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 valid ISO PlainTime strings, 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 mergeIntervalsTime([{ start: "09:00:00", end: "12:00:00" }, { start: "11:00:00", end: "15:00:00" }]) // [{ start: "09:00:00", end: "15:00:00" }]
* @example mergeIntervalsTime([]) // []
* @example mergeIntervalsTime([{ start: "15:00:00", end: "09:00:00" }]) // []
*/
export declare function mergeIntervalsTime(intervals: Array<{
start: string;
end: string;
}>): Array<{
start: string;
end: string;
}>;