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

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

Elixir's `Duration` is an amount of time in calendar units, which is
exactly what the PostgreSQL `interval` type stores. Storing a duration
as an `interval` rather than a number of seconds keeps its calendar
meaning — "one month" is a month, not thirty days — and lets the
database add it to a date or sum a column of them.

For the localized `t:Localize.Duration.t/0` struct, see
`Localize.Duration.Ecto.Type`.

### Schema

    # in a migration
    add :retention, :interval

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

### Normalization

PostgreSQL `interval` keeps three components — months, days and time —
so units within a component are interchangeable: ninety minutes loads
back as one hour and thirty minutes, and a week loads back as seven
days (`interval` has no separate week). The month and day components
are kept distinct, because PostgreSQL applies them separately when an
interval is added to a date. A duration already in this normal form
round-trips unchanged.

# `embed_as`

# `equal?`

---

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