operatingIntervals
Signature
Section titled “Signature”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 inholidayshas no windows; a date with an override has exactly the override’s windows, holiday or not.holidaysmay be aBusinessCalendar, whoseholidaysare 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;
recurringWindowsstates 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 inZ, except a clipped edge, which isrange’s own string. []is both a legitimate result (closed throughout, or an emptyrange) and the sentinel.- Returns
[]whenscheduleis not a validOperatingSchedule(a weekday key other than"1"–"7", a malformed window, an invalid zone, holiday or override date, or two overrides for one date), whenrangeis not a validInterval, whendisambiguationis not one of the four values, and when the range spans more than 10,000 local dates (about 27 years) counted from the daterange.startfalls 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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
schedule | OperatingSchedule | { timeZone, weekly, holidays?, overrides? } operating schedule |
range | Interval | { start, end } record of ISO 8601 instant strings to expand the schedule inside |
Options
Section titled “Options”optionsArg
How a window edge on a clock change is resolved
| Option | Type | Default | Description |
|---|---|---|---|
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. |
Returns
Section titled “Returns”sorted, merged { start, end } records of the open instants, or [] on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”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