intervalXorDateTime
Signature
Section titled “Signature”intervalXorDateTime(aStart: string, aEnd: string, bStart: string, bEnd: string): { start: string; end: string; }[]Return the symmetric difference of two datetime intervals — time covered by exactly one interval.
- Half-open: an interval holds every
twithstart <= t < end. The result is every maximal run covered by exactly one of the two intervals, sorted by start — the same set as CORE-6’smergeIntervals([...subtractIntervals(a, [b]), ...subtractIntervals(b, [a])]). - Pieces end exactly where the other interval starts; no piece is stepped by one nanosecond.
- Touching intervals (
aEnd === bStart) share nothing, so they return one combined run. - Returns
[]when the intervals are identical. An empty interval contributes nothing. - Returns
[]if either interval is invalid (start > end). - Returns
[]on invalid input (wrong type, malformed strings).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
aStart | string | ISO 8601 datetime string for the first interval start |
aEnd | string | ISO 8601 datetime string for the first interval end |
bStart | string | ISO 8601 datetime string for the second interval start |
bEnd | string | ISO 8601 datetime string for the second interval end |
Returns
Section titled “Returns”array of { start, end } records representing the symmetric difference, or [] on invalid input
Members of each item
| Member | Type | Description |
|---|---|---|
start | string | The date-time the interval begins at, as an ISO 8601 date-time string with no offset or time zone. |
end | string | The first date-time 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 { intervalXorDateTime } from "@northguild/gmt/plain/interval";
intervalXorDateTime("2024-01-01T09:00:00", "2024-01-01T13:00:00", "2024-01-01T12:00:00", "2024-01-01T17:00:00") // [{ start: "2024-01-01T09:00:00", end: "2024-01-01T12:00:00" }, { start: "2024-01-01T13:00:00", end: "2024-01-01T17:00:00" }]