intervalXorAllDate
Signature
Section titled “Signature”intervalXorAllDate(intervals: { start: string; end: string; }[]): { start: string; end: string; }[]Return the symmetric difference across a list of date intervals — the set of dates covered by an odd number of the input intervals.
- List-form generalization of
intervalXorDate, which is pairwise only. - Half-open: an interval holds every
twithstart <= t < end. The result is every maximal run covered an odd number of times, computed as a coverage-parity sweep over the start and end boundaries. Runs end exactly at a boundary; no boundary is ever stepped by one unit, so an interval may end on the type’s last value without overflow or midnight wrap. - Touching odd runs join into one run; an empty interval (
start === end) contributes nothing. For two intervals this is exactlyintervalXorDate’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 date is covered an even number of times (e.g. two identical intervals cancel out). - Returns
[]whenintervalsis not an array, when any element is not a{ start, end }record of valid ISO PlainDate strings, or when any element hasstart > end. - Accepts RFC 9557 calendar-annotated PlainDate strings — E5 (issue #78). Since the result is date values, every
start/endacross the whole list must carry the same calendar tag (or all be bare ISO); any mismatch returns[](E5 decision of record D4). Coincident sweep events are grouped withTemporal.PlainDate.compare, which orders by ISO date and ignores the calendar.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
intervals | { start: string; end: string; }[] | array of { start, end } records, optionally calendar-annotated |
Returns
Section titled “Returns”array of { start, end } records covered an odd number of times, or [] on invalid input / mismatched calendars
Members of each item
| Member | Type | Description |
|---|---|---|
start | string | The date the interval begins on, as an ISO 8601 date (YYYY-MM-DD). It keeps a calendar annotation such as [u-ca=hebrew] when the inputs carry one. |
end | string | The first date after the interval, in the same format as start. It is exclusive: the interval holds everything from start up to but not including this value. It is always later than start. |
Examples
Section titled “Examples”import { intervalXorAllDate } from "@northguild/gmt/plain/interval";
intervalXorAllDate([{ start: "2024-01-01", end: "2024-01-10" }, { start: "2024-01-05", end: "2024-01-15" }]) // [{ start: "2024-01-01", end: "2024-01-05" }, { start: "2024-01-10", end: "2024-01-15" }]