Cooper.Duration (Cooper v0.7.0)

Copy Markdown View Source

A duration (CASC.md §6.8): 500ms, 1h30m, !duration("5m"), held in nanoseconds.

A value of its own, not a tagged tuple. It was {:duration, ns}, which a document could also write as a tuple, (duration, 5) -- and then the two read back as the same thing. A struct is something no document can write, so a duration is only ever a duration.

iex> {:ok, %{"t" => t}} = Cooper.load_string("#@version = 1.0\nt = 500ms", dotenv: false)
iex> t
%Cooper.Duration{nanoseconds: 500_000_000}
iex> Cooper.Duration.to_milliseconds(t)
500

Summary

Functions

duration in whole milliseconds, truncated -- what most timeouts on the BEAM take.

Types

t()

@type t() :: %Cooper.Duration{nanoseconds: integer()}

Functions

to_milliseconds(duration)

@spec to_milliseconds(t()) :: integer()

duration in whole milliseconds, truncated -- what most timeouts on the BEAM take.

iex> Cooper.Duration.to_milliseconds(%Cooper.Duration{nanoseconds: 1_500_000})
1