Represents a period of 1 month or more.
iex> range = Month.Period.new(~M[2019-01], ~M[2019-03])
{:ok, #Month.Period<~M[2019-01], ~M[2019-03]>}
iex> range.months
[~M[2019-01], ~M[2019-02], ~M[2019-03]]The months field contains all months within the period, inclusive.
If you want a guarantee that the period would cover min 2 months or more,
look at Month.Range data structure instead.
Summary
Functions
Helper functions that returns the months between the two given
months, inclusive. Please make sure from_month is before to_month.
Creates a new Month.Period using given Months as a start and an end.
Sames as new/2 but returs either result or raises an exception.
Shifts the given period forwards or backwards by given number of months.
Checks if the first period is within the second period (inclusive).
Types
Functions
Helper functions that returns the months between the two given
months, inclusive. Please make sure from_month is before to_month.
@spec new(Date.t(), Date.t()) :: {:ok, t()} | {:error, String.t()}
@spec new(Month.t(), Month.t()) :: {:ok, t()} | {:error, String.t()}
Creates a new Month.Period using given Months as a start and an end.
Examples
iex> Month.Period.new(~M[2019-01], ~M[2019-03])
{:ok, #Month.Period<~M[2019-01], ~M[2019-03]>}
iex> Month.Period.new(~M[2019-03], ~M[2019-01])
{:ok, #Month.Period<~M[2019-01], ~M[2019-03]>}
Sames as new/2 but returs either result or raises an exception.
@spec shift(t(), integer()) :: t()
@spec shift(Month.Range.t(), integer()) :: Month.Range.t()
Shifts the given period forwards or backwards by given number of months.
@spec within?(t(), t()) :: boolean()
@spec within?(Month.Range.t(), Month.Range.t()) :: boolean()
@spec within?(Date.t(), t()) :: boolean()
Checks if the first period is within the second period (inclusive).