View Source Moar.Duration (Moar v1.7.0)

A duration is a {time, unit} tuple.

The time is a number and the unit is one of: :nanosecond, :microsecond, :millisecond, :second, :minute, :hour, :day.

Link to this section Summary

Functions

Converts a {duration, time_unit} tuple into a numeric duration, rounding down to the nearest whole number.

Converts a {duration, time_unit} tuple into a string.

Link to this section Types

@type t() :: {time :: number(), unit :: time_unit()}
@type time_unit() ::
  :nanosecond | :microsecond | :millisecond | :second | :minute | :hour | :day

Link to this section Functions

Link to this function

convert(duration, to_unit)

View Source
@spec convert(from :: t(), to :: time_unit()) :: number()

Converts a {duration, time_unit} tuple into a numeric duration, rounding down to the nearest whole number.

Uses System.convert_time_unit/3 under the hood; see its documentation for more details.

iex> Moar.Duration.convert({121, :second}, :minute)
2
@spec to_string({duration :: t(), unit :: time_unit()}) :: String.t()

Converts a {duration, time_unit} tuple into a string.

iex> Moar.Duration.to_string({1, :second})
"1 second"

iex> Moar.Duration.to_string({25, :millisecond})
"25 milliseconds"