Skip to content

intervalXorAllTime

intervalXorAllTime(intervals: { start: string; end: string; }[]): { start: string; end: string; }[]
import { intervalXorAllTime } from "@northguild/gmt/plain/interval";

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.
  • 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 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.
Parameter Type Description
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

intervalXorAllTime([{ start: "09:00:00", end: "12:00:00" }, { start: "11:00:00", end: "15:00:00" }]) // [{ start: "09:00:00", end: "10:59:59.999999999" }, { start: "12:00:00.000000001", end: "15:00:00" }]
intervalXorAllTime([]) // []

plain/interval/intervalXorAllTime.ts