# operatingTimeBetween

Industry: Core

## Signature

```ts
operatingTimeBetween(start: string, end: string, schedule: OperatingSchedule, optionsArg?: { disambiguation?: "compatible" | "earlier" | "later" | "reject" | undefined; }): string
```

Return how much open time `schedule` has between two instants, as an exact ISO duration.

- The open time in the half-open range `[start, end)`: the length of its intersection with `operatingIntervals(schedule, { start, end })`, summed as `sumIntervals` sums. A support ticket raised Friday 16:00 and answered Monday 10:00 on a 09:00–17:00 weekday desk has waited `PT2H` of open time.
- Hours are the largest unit (`PT40H`, not `P1DT16H`): an open-time total has no calendar. Exact to the nanosecond, and elapsed time, not wall-clock distance, so a 00:00–00:00 window on a London fall-back date adds 25 hours.
- Holidays and overrides apply as in `operatingIntervals`.
- `start === end` returns `"PT0S"`.
- Returns `""` on invalid input: an invalid instant, an `OperatingSchedule` that `isValidOperatingSchedule` refuses, `start` after `end`, a `disambiguation` that is not one of the four values, and a range spanning more than 10,000 local dates (about 27 years) counted from the date `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 |
| --- | --- | --- |
| `start` | `string` | ISO 8601 instant string where the clock starts (inclusive) |
| `end` | `string` | ISO 8601 instant string where the clock stops (exclusive) |
| `schedule` | `OperatingSchedule` | `{ timeZone, weekly, holidays?, overrides? }` operating schedule |

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

ISO 8601 duration string of the open time, 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/)
- [`Disambiguation`](/gmt/reference/types/Disambiguation/)

## Examples

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

operatingTimeBetween("2024-06-14T10:30:00Z", "2024-06-17T04:30:00Z", { timeZone: "Asia/Kolkata", weekly: { 1: [{ from: "09:00", to: "17:00" }], 5: [{ from: "09:00", to: "17:00" }] } }) // "PT2H" — Friday 16:00 to Monday 10:00 local
```

## Source

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