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 type

t() View Source
t() :: %Month.Period{end: Month.t(), months: [Month.t()], start: Month.t()}

Link to this section Functions

Helper functions that returns the months between the two given months, inclusive. Please make sure from_month is before to_month.

Link to this function

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()}

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.

Shifts the given period forwards or backwards by given number of months.

Checks if the first period is within the second period (inclusive).