Periods.Period (Periods v0.2.0)

Copy Markdown View Source

A struct representing an increment of time as an integer amount of a unit.

The unit is one of Periods.all_units/0 (:millisecond through :decade) and the amount is always an integer, which may be negative. Build Periods with Periods.new/1, Periods.new/2, or their raising variants rather than constructing the struct directly.

Periods implement the Inspect and String.Chars protocols:

iex> inspect(%Periods.Period{amount: 10, unit: :day})
"#Periods.Period<10 day>"

iex> to_string(%Periods.Period{amount: 1, unit: :day})
"1 day"

Summary

Types

t()

@type t() :: %Periods.Period{amount: integer(), unit: atom()}