# nextCloseAt

Industry: Core

## Signature

```ts
nextCloseAt(isoString: string, schedule: OperatingSchedule, optionsArg?: { within?: string; disambiguation?: "compatible" | "earlier" | "later" | "reject" | undefined; }): string
```

Return the first instant at or after `isoString` that `schedule` is closed, as a UTC instant.

- Open at `isoString`: returns the end of the open interval holding it — when the gate closes. Windows that touch are one interval, so a schedule open 00:00–00:00 every day closes only where a day has no window.
- Already closed at `isoString`: returns `isoString` itself, in UTC. Pair it with `nextOpenAt` to find the next open interval: `nextCloseAt(nextOpenAt(t, s), s)`.
- Returns `""` when the schedule stays open past the search horizon — a schedule open around the clock never closes.
- Holidays and overrides apply as in `operatingIntervals`.
- `isoString` is an instant: an offset (`Z`, `±HH:MM`) is required.
- Returns `""` on invalid input: an invalid instant, an `OperatingSchedule` that `isValidOperatingSchedule` refuses, a `within` that is not a non-negative ISO duration, a `disambiguation` that 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

| Parameter | Type | Description |
| --- | --- | --- |
| `isoString` | `string` | ISO 8601 instant string to search from, inclusive |
| `schedule` | `OperatingSchedule` | `{ timeZone, weekly, holidays?, overrides? }` operating schedule |

## 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 `isoString` the search may go, as a non-negative ISO 8601 duration added in the schedule's zone, so `"P1D"` is one local day. A closing exactly at that horizon counts, and a horizon past Temporal's last instant stops there. |
| `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 could keep the schedule open past the answer. |

## Returns

UTC instant string ending in "Z", or "" when none within the horizon 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 { nextCloseAt } from "@northguild/gmt/calendar/hours";

nextCloseAt("2024-06-17T08:00:00Z", { timeZone: "Africa/Johannesburg", weekly: { 1: [{ from: "09:00", to: "17:00" }] } }) // "2024-06-17T15:00:00Z" — Monday 10:00 to 17:00 local
```

## Source

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