@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
30 lines (29 loc) • 1.62 kB
TypeScript
/**
* Return the symmetric difference across a list of datetime intervals — the set of instants
* covered by an odd number of the input intervals.
*
* - List-form generalization of `intervalXorDateTime`, which is pairwise only.
* - Implemented as a coverage sweep: each interval contributes a `+1` at its start and a `-1`
* one nanosecond after its end; the result is every maximal run where the running coverage
* count is odd. For two intervals this reduces to exactly `intervalXorDateTime`'s pairwise
* result.
* - Order of the input list does not matter; the result is sorted by start.
* - Returns `[]` for an empty list, and `[]` when every instant is covered an even number of
* times (e.g. two identical intervals cancel out).
* - Returns `[]` when `intervals` is not an array, when any element is not a
* `{ start, end }` record of valid ISO PlainDateTime strings, or when any element has
* `start > end`.
*
* @param intervals array of `{ start, end }` records
* @returns array of `{ start, end }` records covered an odd number of times, or `[]` on invalid input
*
* @example intervalXorAllDateTime([{ start: "2024-01-01T00:00:00", end: "2024-01-10T00:00:00" }, { start: "2024-01-05T00:00:00", end: "2024-01-15T00:00:00" }]) // [{ start: "2024-01-01T00:00:00", end: "2024-01-04T23:59:59.999999999" }, { start: "2024-01-10T00:00:00.000000001", end: "2024-01-15T00:00:00" }]
* @example intervalXorAllDateTime([]) // []
*/
export declare function intervalXorAllDateTime(intervals: Array<{
start: string;
end: string;
}>): Array<{
start: string;
end: string;
}>;