Oban. Period
(Oban v2.24.1)
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, :minute, :hour, :day, :week, :month, and a plural
variant of each.
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 milliseconds.
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
| :month
| :months
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_milliseconds(t()) :: pos_integer()
Convert a period to milliseconds.
Unlike to_seconds/1, a bare integer is considered milliseconds and returned unchanged; only
unit tuples are expanded.
Examples
iex> Oban.Period.to_milliseconds(1000)
1000
iex> Oban.Period.to_milliseconds({1, :second})
1000
iex> Oban.Period.to_milliseconds({2, :minutes})
120_000
@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