# `Month.Period`
[🔗](https://github.com/svileng/month/blob/2.2.0/lib/month/period.ex#L1)

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.

# `t`

```elixir
@type t() :: %Month.Period{end: Month.t(), months: [Month.t()], start: Month.t()}
```

# `months`

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

# `new`

```elixir
@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 `Month`s 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!`

```elixir
@spec new!(Date.t(), Date.t()) :: t()
@spec new!(Month.t(), Month.t()) :: t()
```

Sames as `new/2` but returs either result or raises an exception.

# `shift`

```elixir
@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.

# `within?`

```elixir
@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).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
