A calendar-relative duration — a list of {unit, amount}
pairs such as [year: 1, month: 6]. Produced by the ISO 8601
parser (P1Y6M), the RRULE encoder (as the FREQ + INTERVAL
cadence), and arithmetic helpers in Tempo.Math.
Summary
Functions
Construct a Tempo.Duration.t/0 from a keyword list of
{unit, amount} pairs.
Bang variant of new/1.
Types
Functions
@spec new(keyword()) :: {:ok, t()} | {:error, Exception.t()}
Construct a Tempo.Duration.t/0 from a keyword list of
{unit, amount} pairs.
Components can be passed in any order; new/1 reorders them
coarse-to-fine before building the struct.
Arguments
componentsis a keyword list of duration units.
Options
Every value must be an integer. Negative values are permitted (reverse-direction duration).
:yearis the year count.:monthis the month count.:weekis the week count.:dayis the day count.:day_of_yearis a day-of-year offset (used by RRULE expansion).:day_of_weekis a day-of-week offset (used by RRULE expansion).:houris the hour count.:minuteis the minute count.:secondis the second count.
Returns
{:ok, t()}on success.{:error, reason}when a key is unknown or a value is not an integer.
Examples
iex> {:ok, d} = Tempo.Duration.new(year: 1, month: 6)
iex> d.time
[year: 1, month: 6]
iex> {:ok, d} = Tempo.Duration.new(month: 6, year: 1)
iex> d.time
[year: 1, month: 6]
Bang variant of new/1.