Month v2.1.0 Month.Period View Source
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.
Link to this section 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)
Link to this section Types
Link to this section Functions
months(from, to) View Source
Helper functions that returns the months between the two given
months, inclusive. Please make sure from_month is before to_month.
new(first, last)
View Source
new(Date.t(), Date.t()) :: {:ok, Month.Period.t()} | {:error, String.t()}
new(Month.t(), Month.t()) :: {:ok, Month.Period.t()} | {:error, String.t()}
new(Date.t(), Date.t()) :: {:ok, Month.Period.t()} | {:error, String.t()}
new(Month.t(), Month.t()) :: {:ok, Month.Period.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]>}
new!(first, last)
View Source
new!(Date.t(), Date.t()) :: Month.Period.t()
new!(Month.t(), Month.t()) :: Month.Period.t()
new!(Date.t(), Date.t()) :: Month.Period.t()
new!(Month.t(), Month.t()) :: Month.Period.t()
Sames as new/2 but returs either result or raises an exception.
shift(period, num_months)
View Source
shift(Month.Period.t(), integer()) :: Month.Period.t()
shift(Month.Range.t(), integer()) :: Month.Range.t()
shift(Month.Period.t(), integer()) :: Month.Period.t()
shift(Month.Range.t(), integer()) :: Month.Range.t()
Shifts the given period forwards or backwards by given number of months.
within?(date, period)
View Source
within?(Month.Period.t(), Month.Period.t()) :: boolean()
within?(Month.Range.t(), Month.Range.t()) :: boolean()
within?(Date.t(), Month.Period.t()) :: boolean()
within?(Month.Period.t(), Month.Period.t()) :: boolean()
within?(Month.Range.t(), Month.Range.t()) :: boolean()
within?(Date.t(), Month.Period.t()) :: boolean()
Checks if the first period is within the second period (inclusive).