View Source Euclid.Duration (Euclid v0.4.0)

A duration is a {time, unit} tuple, where 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. Rounds down to the nearest whole number. Uses System.convert_time_unit/3 under the hood; see its documentation for more details.

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

Link to this section Types

Specs

duration() :: {time :: number(), unit :: time_unit()}

Specs

time_unit() ::
  :nanosecond | :microsecond | :millisecond | :second | :minute | :hour | :day

Link to this section Functions

Link to this function

convert(duration, to_unit)

View Source

Specs

convert(from :: duration(), to :: time_unit()) :: number()

Converts a {duration, time_unit} tuple into a numeric duration. Rounds down to the nearest whole number. Uses System.convert_time_unit/3 under the hood; see its documentation for more details.

Examples

iex> Euclid.Duration.convert({121, :second}, :minute)
2

Specs

to_string({duration :: duration(), unit :: time_unit()}) :: String.t()

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

Examples

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

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