OpenHours.TimeSlot (open_hours v1.0.0)

Copy Markdown View Source

This module contains all functions to work with time slots.

Summary

Types

t()

Struct composed by a start datetime and an end datetime.

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

t()

@type t() :: %OpenHours.TimeSlot{ends_at: DateTime.t(), starts_at: DateTime.t()}

Struct composed by a start datetime and an end datetime.

Functions

between(schedule, starts_at, ends_at)

@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.

next(schedule, at, opts \\ [])

@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 - if true, includes the slot containing the given DateTime (default: true)

Returns a list of %TimeSlot{} structs ordered chronologically.

previous(schedule, at, opts \\ [])

@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 - if true, includes the slot containing the given DateTime (default: true)

Returns a list of %TimeSlot{} structs ordered from most recent to least recent.

stream_next(schedule, at, opts \\ [])

@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 - if true, includes the slot containing the given DateTime (default: true)

Examples

schedule
|> TimeSlot.stream_next(datetime)
|> Enum.take(5)

stream_previous(schedule, at, opts \\ [])

@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 - if true, includes the slot containing the given DateTime (default: true)

Examples

schedule
|> TimeSlot.stream_previous(datetime)
|> Enum.take(5)