addOperatingTime
Signature
Section titled “Signature”addOperatingTime(start: string, duration: string, schedule: OperatingSchedule, optionsArg?: { within?: string; disambiguation?: "compatible" | "earlier" | "later" | "reject" | undefined; }): stringReturn the instant at which duration of open time has elapsed since start: the deadline of a service level measured in working hours.
- The earliest instant
Xsuch thatoperatingTimeBetween(start, X, schedule)equalsduration. The clock stops while the schedule is closed and resumes when it reopens, so an eight-hour SLA raised at Friday 16:00 on a 09:00–17:00 weekday desk falls due on Monday at 16:00. A deadline that lands exactly on a closing time is that closing instant, not the next opening. durationis hours and smaller units ("PT8H","PT90M"). A duration with days, weeks, months or years returns"":P1Dof open time could mean 24 open hours or one working day, and GMT does not guess."PT0S"returnsstartitself, in UTC.- Returns
""when the deadline would fall past the search horizon, rather than searching forever. - Holidays and overrides apply as in
operatingIntervals. - Returns
""on invalid input: an invalid instant, duration orOperatingSchedule, a negativeduration, awithinthat is not a non-negative ISO duration, adisambiguationthat is not one of the four values, and a search that would go more than 10,000 local dates past the input’s date. - 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 last instant Temporal supports (
+275760-09-13T00:00:00Z) for an offset east of UTC, or of the first (-271821-04-20T00:00:00Z) for one west, this returns"". An offset to the minute has no such limit.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
start | string | ISO 8601 instant string where the clock starts |
duration | string | ISO 8601 duration of open time, hours and smaller units (e.g. “PT8H”) |
schedule | OperatingSchedule | { timeZone, weekly, holidays?, overrides? } operating schedule |
Options
Section titled “Options”optionsArg
How far the search goes, and how a window edge on a clock change is resolved
| Option | Type | Default | Description |
|---|---|---|---|
within? | string | "P1Y" | How far after start the search may go, as a non-negative ISO 8601 duration added in the schedule’s zone, so "P1D" is one local day. A deadline exactly at that horizon counts, and a horizon past Temporal’s last instant stops there. |
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 could add open time before the deadline. |
Returns
Section titled “Returns”UTC instant string ending in “Z”, or "" when past the horizon or on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”import { addOperatingTime } from "@northguild/gmt/calendar/hours";
addOperatingTime("2024-06-14T20:00:00Z", "PT2H", { timeZone: "America/New_York", weekly: { 1: [{ from: "09:00", to: "17:00" }], 5: [{ from: "09:00", to: "17:00" }] } }) // "2024-06-17T14:00:00Z" — Friday 16:00 to Monday 10:00 local