hocon v0.1.8 Hocon.Period View Source

This structure contains the period defined by years, months and days. It is the result of the Hocon.get_period/2 and Hocon.as_period/1 function. You can use it to calculate new dates. Unfortenly Elixir Date Library does not support adding other units like months or years. It supports only days:

Example

iex> conf = Hocon.decode!(~s(max_period = 3days))
%{"max_period" => "3days"}
iex> %Hocon.Period{days: days, months: _, years: _} = Hocon.get_period(conf, "max_period")
%Hocon.Period{days: 3, months: 0, years: 0}
iex> Date.add(~D[2000-02-27], days)
~D[2000-03-01]

A better alternative is timex:

Example

iex> conf = Hocon.decode!(~s(max_period = 1m))
%{"max_period" => "1m"}
iex> %Hocon.Period{days: _, months: months, years: _} = Hocon.get_period(conf, "max_period")
%Hocon.Period{days: 0, months: 1, years: 0}
iex> Date.add(~D[2000-02-27], days)
Timex.shift(~D[2000-11-29], months: 3)
~D[2001-02-28]

Link to this section Summary

Functions

Returns a period for days.

Returns a period for months.

Returns a period for weeks. The weeks are multiplied by 7.

Returns a period for years.

Link to this section Functions

Returns a period for days.

Returns a period for months.

Returns a period for weeks. The weeks are multiplied by 7.

Returns a period for years.