An Ecto.Type storing an Elixir 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 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.DurationNormalization
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.
Summary
Functions
Callback implementation for Ecto.Type.embed_as/1.
Callback implementation for Ecto.Type.equal?/2.
Functions
Callback implementation for Ecto.Type.embed_as/1.
Callback implementation for Ecto.Type.equal?/2.