# operatingIntervals

Industry: Core

## Signature

```ts
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; `isValidOperatingSchedule` tells a closed schedule from an invalid one.
- 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; `isValidOperatingSchedule` lists every rule), 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.

## 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

**optionsArg**

How a window edge on a clock change is resolved

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `disambiguation?` | `"compatible"` \| `"earlier"` \| `"later"` \| `"reject"` ([`Disambiguation`](/gmt/reference/types/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

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

## Related types

- [`OperatingSchedule`](/gmt/reference/types/OperatingSchedule/)
- [`IsoWeekday`](/gmt/reference/types/IsoWeekday/)
- [`LocalWindow`](/gmt/reference/types/LocalWindow/)
- [`BusinessCalendar`](/gmt/reference/types/BusinessCalendar/)
- [`OperatingOverride`](/gmt/reference/types/OperatingOverride/)
- [`Interval`](/gmt/reference/types/Interval/)
- [`Disambiguation`](/gmt/reference/types/Disambiguation/)

## Examples

```ts
import { operatingIntervals } from "@northguild/gmt/calendar/hours";

operatingIntervals({ timeZone: "Africa/Kigali", 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-05T07:00:00Z", end: "2024-07-05T15:00:00Z" }] — the holiday is closed
```

## Source

[calendar/hours/operatingIntervals.ts](https://github.com/northguild/gmt/blob/main/packages/gmt/src/calendar/hours/operatingIntervals.ts)
