Skip to content

operatingIntervals

operatingIntervals(schedule: OperatingSchedule, range: Interval, optionsArg?: { disambiguation?: "compatible" | "earlier" | "later" | "reject" | undefined; }): Interval[]

Return the instants an OperatingSchedule is open inside range: its weekly windows with holidays closed and overrides applied, resolved in the schedule’s zone.

  • Works date by date in schedule.timeZone. A date listed in holidays has no windows; a date with an override has exactly the override’s windows, holiday or not. holidays may be a BusinessCalendar, whose holidays are read.
  • A window belongs to the date it starts on, so a holiday or override on Friday removes or replaces a Friday 23:00–06:00 window, and one on Saturday leaves it alone.
  • Window edges are local wall times; recurringWindows states the window rules in full.
  • The result is clipped to range (half-open), sorted, and merged where windows overlap or touch. Endpoints are UTC instants ending in Z, except a clipped edge, which is range’s own string.
  • [] is both a legitimate result (closed throughout, or an empty range) and the sentinel.
  • Returns [] when schedule is not a valid OperatingSchedule (a weekday key other than "1"–"7", a malformed window, an invalid zone, holiday or override date, or two overrides for one date), when range is not a valid Interval, when disambiguation is not one of the four values, and when the range spans more than 10,000 local dates (about 27 years) counted from the date range.start falls on.
  • Limit at an offset with seconds. The instant is placed in the offset’s whole-minute zone, moved by its seconds, and the moved instant must be inside Temporal’s range. So within the offset’s seconds (under a minute) of the first instant Temporal supports (-271821-04-20T00:00:00Z), for an offset west of UTC, this returns []. An offset to the minute has no such limit.
ParameterTypeDescription
scheduleOperatingSchedule{ timeZone, weekly, holidays?, overrides? } operating schedule
rangeInterval{ start, end } record of ISO 8601 instant strings to expand the schedule inside

optionsArg

How a window edge on a clock change is resolved

OptionTypeDefaultDescription
disambiguation?"compatible" | "earlier" | "later" | "reject" (Disambiguation)"compatible", Temporal’s default.How a window edge in a repeated or skipped local hour becomes an instant, as resolveLocal resolves it. "compatible" takes the earlier instant of a repeated fall-back hour and the later one of a skipped spring-forward hour, and "earlier" and "later" take that side in both cases. "reject" returns [] when a window with such an edge reaches the range.

sorted, merged { start, end } records of the open instants, or [] on invalid input

import { operatingIntervals } from "@northguild/gmt/calendar/hours";
operatingIntervals({ timeZone: "America/New_York", weekly: { 4: [{ from: "09:00", to: "17:00" }], 5: [{ from: "09:00", to: "17:00" }] }, holidays: ["2024-07-04"] }, { start: "2024-07-04T00:00:00Z", end: "2024-07-06T00:00:00Z" }) // [{ start: "2024-07-05T13:00:00Z", end: "2024-07-05T21:00:00Z" }] — the holiday is closed
output 

calendar/hours/operatingIntervals.ts