This module contains functions to calculate business time duration.
Summary
Functions
Calculates the business time elapsed between two DateTimes, in seconds.
Functions
@spec between(OpenHours.Schedule.t(), DateTime.t(), DateTime.t()) :: non_neg_integer()
Calculates the business time elapsed between two DateTimes, in seconds.
Only time that falls within business hours (as defined by the schedule) is counted. Non-working hours, weekends, holidays, and breaks are excluded.
Examples
iex> schedule = %OpenHours.Schedule{
...> hours: %{
...> mon: [{~T[09:00:00], ~T[17:00:00]}],
...> tue: [{~T[09:00:00], ~T[17:00:00]}]
...> },
...> time_zone: "Etc/UTC"
...> }
iex> starts_at = DateTime.from_naive!(~N[2026-03-16 10:00:00], "Etc/UTC")
iex> ends_at = DateTime.from_naive!(~N[2026-03-16 15:00:00], "Etc/UTC")
iex> OpenHours.Duration.between(schedule, starts_at, ends_at)
18000