# `OpenHours.Schedule`
[🔗](https://github.com/hopsor/open_hours/blob/v1.0.1/lib/open_hours/schedule.ex#L1)

This module contains functions to work with schedules.

There are five settings to configure a schedule.

- `hours`: Map containing all the open hours intervals for a regular week.
- `holidays`: Dates in which the business is closed.
- `shifts`: Special dates where the business has a different hour schedule.
- `breaks`: Special dates where the business has interruption intervals.
- `time_zone`: Time zone of the schedule.

All the `%Time{}` values used for the schedule must be in local time.

# `break`

```elixir
@type break() :: {Date.t(), [OpenHours.Interval.t()]}
```

A tuple formed by a date and a list of intervals

# `breaks`

```elixir
@type breaks() :: [break()]
```

A list of breaks

# `holidays`

```elixir
@type holidays() :: [Date.t()]
```

A list of Date structs representing the days the business is closed

# `hour_schedule`

```elixir
@type hour_schedule() :: %{
  optional(:mon) =&gt; [OpenHours.Interval.t()],
  optional(:tue) =&gt; [OpenHours.Interval.t()],
  optional(:wed) =&gt; [OpenHours.Interval.t()],
  optional(:thu) =&gt; [OpenHours.Interval.t()],
  optional(:fri) =&gt; [OpenHours.Interval.t()],
  optional(:sat) =&gt; [OpenHours.Interval.t()],
  optional(:sun) =&gt; [OpenHours.Interval.t()]
}
```

A struct representing the regular weekly schedule. Each key corresponds with the three first
characters of a week day. The values of each key are composed by lists of intervals.

# `shift`

```elixir
@type shift() :: {Date.t(), [OpenHours.Interval.t()]}
```

A tuple formed by a date and a list of intervals

# `shifts`

```elixir
@type shifts() :: [shift()]
```

A list of shifts

# `t`

```elixir
@type t() :: %OpenHours.Schedule{
  breaks: breaks(),
  holidays: holidays(),
  hours: hour_schedule(),
  shifts: shifts(),
  time_zone: time_zone()
}
```

A struct containing all data of a schedule

# `time_zone`

```elixir
@type time_zone() :: String.t()
```

A string containing a valid IANA time zone

# `in_hours?`

```elixir
@spec in_hours?(t(), DateTime.t()) :: boolean()
```

It returns `true` if the supplied `%DateTime{}` is within the business hours. The result is
calculated based on all the settings of the schedule (hours, shifts, breaks and holidays).

The rules applied to establish if the date passed is in business hours is the following.

Shifts act as exceptions to the hours configured for a particular date; that is, if a date is
configured with both hours-based intervals and shifts, the shifts are in force and the intervals
are disregarded.

Periods occurring on holidays are disregarded.

Periods that overlaps with a break are treated as inactive. In case a date overlaps with a shift
and a break the shift will have priority. Priority works as follows:

Holidays > Shifts > Breaks > Hours

---

*Consult [api-reference.md](api-reference.md) for complete listing*
