@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
38 lines (37 loc) • 2.44 kB
TypeScript
/**
* Return the symmetric difference across a list of zoned intervals — the set of instants
* covered by an odd number of the input intervals.
*
* - List-form generalization of `intervalXorZoned`, which is pairwise only.
* - Implemented as a coverage sweep over instants: each interval contributes a `+1` at its
* start instant and a `-1` one nanosecond after its end instant; the result is every maximal
* run where the running coverage count is odd. For two intervals this reduces to exactly
* `intervalXorZoned`'s pairwise result.
* - Output boundaries carry the time zone of whichever input interval contributed them.
* - Order of the input list does not matter; the result is sorted by start instant.
* - 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 ZonedDateTime strings, or when any element has
* `start > end` or a leap-second string.
* - Accepts GMT calendar-annotated zoned strings (as produced by `convertZonedToCalendar`) as
* well as bare ISO ones — E7 (issue #152) — but **rejects a mismatched set**: every endpoint in
* the list must name the same calendar system (E7's D4-zoned). This function returns *values*
* the caller reads back as datetimes, and an array whose elements carried different calendar
* tags would be unreadable as a set. A mismatch returns `[]`.
* - Output boundaries are re-derived in the resolved calendar via `formatZonedInCalendar`, never
* copied from an input string (E7's D7-zoned).
*
* @param intervals array of `{ start, end }` records
* @returns array of `{ start, end }` records covered an odd number of times, or `[]` on invalid input
*
* @example intervalXorAllZoned([{ start: "2024-01-01T00:00:00+00:00[UTC]", end: "2024-01-10T00:00:00+00:00[UTC]" }, { start: "2024-01-05T00:00:00+00:00[UTC]", end: "2024-01-15T00:00:00+00:00[UTC]" }]) // [{ start: "2024-01-01T00:00:00+00:00[UTC]", end: "2024-01-04T23:59:59.999999999+00:00[UTC]" }, { start: "2024-01-10T00:00:00.000000001+00:00[UTC]", end: "2024-01-15T00:00:00+00:00[UTC]" }]
* @example intervalXorAllZoned([]) // []
*/
export declare function intervalXorAllZoned(intervals: Array<{
start: string;
end: string;
}>): Array<{
start: string;
end: string;
}>;