# isValidOperatingSchedule

Industry: Core

## Signature

```ts
isValidOperatingSchedule(schedule: unknown): schedule is OperatingSchedule
```

Return true when `schedule` is an `OperatingSchedule` the operating-hours functions accept.

- `timeZone` must be a time zone identifier (`"Europe/Paris"`, `"+05:30"`, `"+0530"`, `"-08"`) or a stored offset `±HH:MM[:SS]` (`"-00:44:30"`), as `isValidTimeZone` or `isValidUtcOffset` accepts.
- `weekly` must be an object whose own enumerable keys are `"1"`–`"7"`, Monday to Sunday. A weekday is read with a property get, so an inherited one applies. A weekday that is absent or `undefined` is closed; any other value must be an array of windows. `{}` is valid and is closed every day. A `Map` has no such keys, so it is valid and reads as closed every day.
- A window is `{ from, to }`, both plain times (`"HH:MM"` or `"HH:MM:SS"` with an optional fraction). `to` at or before `from` crosses midnight; `"00:00"` to `"00:00"` is a whole day. `"24:00"`, a second of 60 and a time with an offset or `T` are not plain times.
- `holidays` is optional: an array of ISO PlainDate strings, or a `BusinessCalendar`, which must pass `isValidBusinessCalendar` though only its `holidays` are read.
- `overrides` is optional: an array of `{ date, windows }`. Two overrides for one date, however the date is spelt, are invalid.
- Dates take no annotation (`"2024-05-15[u-ca=iso8601]"` is invalid) and lie between `-271821-04-19` and `+275760-09-13`, Temporal's limits.
- Other keys on the schedule, a window or an override are ignored, so a misspelt key such as `holiday` is not an error.
- Returns `false` for non-objects, `null` and arrays. A function carrying the fields is accepted.
- Use it to tell a closed schedule from an invalid one: `operatingIntervals` returns `[]` and `isOpenAt` returns `false` for both. `nextOpenAt`, `nextCloseAt` and `addOperatingTime` search a horizon and return `""` for an invalid schedule and for no answer within it. `operatingTimeBetween` has no horizon: it returns `""` for an invalid schedule and `"PT0S"` for a valid closed one.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `schedule` | `unknown` | candidate value of any type |

## Returns

boolean indicating whether every operating-hours function accepts it

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

## Examples

```ts
import { isValidOperatingSchedule } from "@northguild/gmt/calendar/validate";

isValidOperatingSchedule({ timeZone: "Europe/Paris", weekly: { 1: [{ from: "09:00", to: "17:00" }] } }) // true
```

## Source

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