OpenHours.Schedule (open_hours v0.1.2)
View SourceThis 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.
Summary
Types
A tuple formed by a date and a list of intervals
A list of breaks
A list of Date structs representing the days the business is closed
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.
A tuple formed by a date and a list of intervals
A list of shifts
A struct containing all data of a schedule
A string containing a valid IANA time zone
Functions
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).
Types
@type break() :: {Date.t(), [OpenHours.Interval.t()]}
A tuple formed by a date and a list of intervals
@type breaks() :: [break()]
A list of breaks
@type holidays() :: [Date.t()]
A list of Date structs representing the days the business is closed
@type hour_schedule() :: %{ optional(:mon) => [OpenHours.Interval.t()], optional(:tue) => [OpenHours.Interval.t()], optional(:wed) => [OpenHours.Interval.t()], optional(:thu) => [OpenHours.Interval.t()], optional(:fri) => [OpenHours.Interval.t()], optional(:sat) => [OpenHours.Interval.t()], optional(:sun) => [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.
@type shift() :: {Date.t(), [OpenHours.Interval.t()]}
A tuple formed by a date and a list of intervals
@type shifts() :: [shift()]
A list of shifts
@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
@type time_zone() :: String.t()
A string containing a valid IANA time zone
Functions
@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