UNPKG

@burglekitt/gmt

Version:

Temporal-based date and time utilities with timezone support and polyfill integration

32 lines (31 loc) 2 kB
/** * Collapse a list of date intervals into the minimum set of non-overlapping intervals. * * - List-form generalization of `intervalUnionDate`, which is pairwise only. * - Intervals are merged when they overlap or share an endpoint exactly (adjacent intervals, * e.g. `aEnd === bStart`, ARE merged — same rule as `intervalUnionDate`). * - 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 PlainDate strings, or when any element has * `start > end`. * - Accepts GMT calendar-annotated PlainDate strings — E5 (issue #78). Since the result is * date *values*, every `start`/`end` across the whole list must carry the *same* calendar tag * (or all be bare ISO); any mismatch returns `[]` (E5 decision of record D4). * * @param intervals array of `{ start, end }` records, optionally calendar-annotated * @returns the minimum set of non-overlapping `{ start, end }` records, sorted by start, or `[]` on invalid input / mismatched calendars * * @example mergeIntervalsDate([{ start: "2024-01-01", end: "2024-01-10" }, { start: "2024-01-05", end: "2024-01-15" }]) // [{ start: "2024-01-01", end: "2024-01-15" }] * @example mergeIntervalsDate([{ start: "2024-01-01", end: "2024-01-10" }, { start: "2024-01-10", end: "2024-01-20" }]) // [{ start: "2024-01-01", end: "2024-01-20" }] (adjacent, merged) * @example mergeIntervalsDate([{ start: "2024-01-01", end: "2024-01-05" }, { start: "2024-01-10", end: "2024-01-15" }]) // [{ start: "2024-01-01", end: "2024-01-05" }, { start: "2024-01-10", end: "2024-01-15" }] (disjoint) * @example mergeIntervalsDate([]) // [] * @example mergeIntervalsDate([{ start: "2024-01-10", end: "2024-01-01" }]) // [] */ export declare function mergeIntervalsDate(intervals: Array<{ start: string; end: string; }>): Array<{ start: string; end: string; }>;