Unit.Time (Hyper v0.1.0)

Copy Markdown View Source

A duration, stored canonically in nanoseconds. Build with ns/1/us/1/ms/1/s/1, read back with the matching as_* accessor. A Time is a distinct struct, so it cannot be mixed with other dimensions (Information, Bandwidth). Arithmetic (+, -) and comparison (<, >, <=, >=) come from Unit.Operators.

Summary

Functions

Parse a duration string like "60s"/"100ms"/"1h". Suffixes: ns/us/ms/s/m/h.

Like parse/1 but raises ArgumentError on bad input.

The zero duration (additive identity).

Types

t()

@opaque t()

Functions

as_ms(time)

@spec as_ms(t()) :: integer()

as_ns(time)

@spec as_ns(t()) :: integer()

as_s(time)

@spec as_s(t()) :: integer()

as_us(time)

@spec as_us(t()) :: integer()

ms(v)

@spec ms(integer()) :: t()

ns(v)

@spec ns(integer()) :: t()

parse(s)

@spec parse(String.t()) :: {:ok, t()} | {:error, {:bad_unit, String.t()}}

Parse a duration string like "60s"/"100ms"/"1h". Suffixes: ns/us/ms/s/m/h.

parse!(s)

@spec parse!(String.t()) :: t()

Like parse/1 but raises ArgumentError on bad input.

s(v)

@spec s(integer()) :: t()

us(v)

@spec us(integer()) :: t()

zero()

@spec zero() :: t()

The zero duration (additive identity).