Oban.Period
(Oban v2.21.0)
View Source
Periods represent durations of time as either raw seconds or a unit tuple.
All periods are normalized to seconds internally. The tuple format provides a more expressive way to specify durations in larger units:
# Raw seconds
60
# Unit tuple
{1, :minute}
{5, :minutes}
{2, :hours}Supported time units are :second, :seconds, :minute, :minutes, :hour, :hours,
:day, :days, :week, and :weeks.
Summary
Functions
Checks whether the given value is a non-negative integer suitable for seconds.
Checks whether the given value is a valid period, either seconds or a unit tuple.
Convert a period to seconds.
Types
@type t() :: pos_integer() | {pos_integer(), time_unit()}
A time duration as seconds or a unit tuple.
@type time_unit() ::
:second
| :seconds
| :minute
| :minutes
| :hour
| :hours
| :day
| :days
| :week
| :weeks
Supported time units for period tuples.
Both singular and plural forms are accepted, e.g. :minute and :minutes.
Functions
Checks whether the given value is a non-negative integer suitable for seconds.
Checks whether the given value is a valid period, either seconds or a unit tuple.
@spec to_seconds(t()) :: pos_integer()
Convert a period to seconds.
Examples
iex> Oban.Period.to_seconds(60)
60
iex> Oban.Period.to_seconds({1, :minute})
60
iex> Oban.Period.to_seconds({2, :hours})
7200