Skip to content

operatingTimeBetween

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 New York fall-back date adds 25 hours.
  • Holidays and overrides apply as in operatingIntervals.
  • start === end returns "PT0S".
  • Returns "" on invalid input: an invalid instant or OperatingSchedule, 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.
ParameterTypeDescription
startstringISO 8601 instant string where the clock starts (inclusive)
endstringISO 8601 instant string where the clock stops (exclusive)
scheduleOperatingSchedule{ timeZone, weekly, holidays?, overrides? } operating schedule

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.

ISO 8601 duration string of the open time, or "" on invalid input

import { operatingTimeBetween } from "@northguild/gmt/calendar/hours";
operatingTimeBetween("2024-06-14T20:00:00Z", "2024-06-17T14:00:00Z", { timeZone: "America/New_York", weekly: { 1: [{ from: "09:00", to: "17:00" }], 5: [{ from: "09:00", to: "17:00" }] } }) // "PT2H" — Friday 16:00 to Monday 10:00 local
output 

calendar/hours/operatingTimeBetween.ts