# `Localize.Duration.Ecto.Type`
[🔗](https://github.com/elixir-localize/localize_sql/blob/v1.0.1/lib/localize/duration/ecto/type.ex#L2)

An `Ecto.Type` storing a `t:Localize.Duration.t/0` in a PostgreSQL
`interval` column.

A `Localize.Duration` is an amount of time in calendar units — a year,
three months, two days — and `interval` is the PostgreSQL type for
exactly that. Storing one as an `interval` rather than a number of
seconds keeps the calendar meaning that "one month" carries (a month
is not always thirty days), and lets the database add an interval to a
date or sum a column of them.

### Schema

    # in a migration
    add :billing_period, :interval

    # in a schema
    field :billing_period, Localize.Duration.Ecto.Type

### Normalization

PostgreSQL `interval` keeps three components — months, days and time —
so the units within each component are interchangeable: a duration of
ninety minutes is stored as, and loaded back as, one hour and thirty
minutes, and thirteen months as one year and one month. Durations that
are already in their normal form round-trip unchanged. The day and
month components are kept distinct — a month is never folded into days
— because PostgreSQL applies them separately when an interval is added
to a date.

# `embed_as`

# `equal?`

---

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