This module contains all functions to work with time slots.
Summary
Functions
Calculates a list of time slots between two dates based on a Schedule. It follows the same rules
as OpenHours.Schedule.in_hours?/2.
Returns the next time slots from the given DateTime, looking forward in the schedule.
Returns the previous time slots from the given DateTime, looking backward in the schedule.
Returns a lazy stream of time slots from the given DateTime, looking forward in the schedule.
Returns a lazy stream of time slots from the given DateTime, looking backward in the schedule.
Types
@type t() :: %OpenHours.TimeSlot{ends_at: DateTime.t(), starts_at: DateTime.t()}
Struct composed by a start datetime and an end datetime.
Functions
@spec between(OpenHours.Schedule.t(), DateTime.t(), DateTime.t()) :: [t()]
Calculates a list of time slots between two dates based on a Schedule. It follows the same rules
as OpenHours.Schedule.in_hours?/2.
@spec next(OpenHours.Schedule.t(), DateTime.t(), keyword()) :: [t()]
Returns the next time slots from the given DateTime, looking forward in the schedule.
Options
:limit- number of slots to return (default:1):include_overlap- iftrue, includes the slot containing the given DateTime (default:true)
Returns a list of %TimeSlot{} structs ordered chronologically.
@spec previous(OpenHours.Schedule.t(), DateTime.t(), keyword()) :: [t()]
Returns the previous time slots from the given DateTime, looking backward in the schedule.
Options
:limit- number of slots to return (default:1):include_overlap- iftrue, includes the slot containing the given DateTime (default:true)
Returns a list of %TimeSlot{} structs ordered from most recent to least recent.
@spec stream_next(OpenHours.Schedule.t(), DateTime.t(), keyword()) :: Enumerable.t()
Returns a lazy stream of time slots from the given DateTime, looking forward in the schedule.
The stream is infinite and respects holidays, shifts, and breaks.
Options
:include_overlap- iftrue, includes the slot containing the given DateTime (default:true)
Examples
schedule
|> TimeSlot.stream_next(datetime)
|> Enum.take(5)
@spec stream_previous(OpenHours.Schedule.t(), DateTime.t(), keyword()) :: Enumerable.t()
Returns a lazy stream of time slots from the given DateTime, looking backward in the schedule.
The stream is infinite and respects holidays, shifts, and breaks.
Options
:include_overlap- iftrue, includes the slot containing the given DateTime (default:true)
Examples
schedule
|> TimeSlot.stream_previous(datetime)
|> Enum.take(5)