Skip to content

intervalXorAllTime

intervalXorAllTime(intervals: { start: string; end: string; }[]): { start: string; end: string; }[]

Return the symmetric difference across a list of time intervals — the set of clock times covered by an odd number of the input intervals.

  • List-form generalization of intervalXorTime, which is pairwise only.
  • Half-open: an interval holds every t with start <= 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 exactly intervalXorTime’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 clock time 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 PlainTime strings, or when any element has start > end.
ParameterTypeDescription
intervals{ start: string; end: string; }[]array of { start, end } records

array of { start, end } records covered an odd number of times, or [] on invalid input

Members of each item

MemberTypeDescription
startstringThe clock time the interval begins at, as an ISO 8601 time string with no date, offset or time zone.
endstringThe first clock 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.
import { intervalXorAllTime } from "@northguild/gmt/plain/interval";
intervalXorAllTime([{ start: "09:00:00", end: "12:00:00" }, { start: "11:00:00", end: "15:00:00" }]) // [{ start: "09:00:00", end: "11:00:00" }, { start: "12:00:00", end: "15:00:00" }]
intervals
output 

plain/interval/intervalXorAllTime.ts