# `Tempo.Ecto.Tempo`
[🔗](https://github.com/elixir-tempo/tempo_sql/blob/v0.4.0/lib/tempo/ecto/tempo.ex#L2)

Ecto.ParameterizedType for persisting a value as a PostgreSQL
`tstzrange`: `Tempo.Ecto.Interval` under the name `tempo_sql` 0.2.0
gave a column of bare values, kept so that schemas written for it
still compile.

A value is the span it names — `~o"2026Y"` the whole of 2026,
`~o"2026Y-06M"` June 2026 — and is stored as that interval, as
`Tempo.Ecto.Interval` stores it.

## Usage

    schema "years" do
      field :reporting_year, Tempo.Ecto.Tempo, resolution: :year
    end

## Options

  * `:resolution` — as for `Tempo.Ecto.Interval`. With `:year`, a
    year loads as the interval from that year through itself.

  * `:frame` — as for `Tempo.Ecto.Interval`: `:utc` (the default)
    for a `tstzrange` column, `:floating` for a `tsrange` column.

## Round-trip caveat

A stored `~o"2026Y"` loads back as the interval it names, not the
value: a `tstzrange` keeps no more. `Tempo.Ecto.TempoRange` keeps
the value as it was written.

# `cast_type`

```elixir
@spec cast_type(keyword()) :: Ecto.Type.t()
```

Builds the parameterized-type tuple for use outside a schema.

See `Tempo.Ecto.Interval.cast_type/1` for the schema-side
equivalent and the full discussion.

### Arguments

* `options` is a keyword list of options.

### Options

* `:resolution` writes the ends to the given unit on load. One of
  `:year`, `:month`, `:day`, `:hour`, `:minute`, or `:second`.
  Defaults to `:second`.

* `:frame` is `:utc` (the default) for a `tstzrange` column or
  `:floating` for a `tsrange` column.

### Returns

* A `t:Ecto.ParameterizedType.opts/0` tuple.

### Examples

    iex> Tempo.Ecto.Tempo.cast_type()
    {:parameterized, {Tempo.Ecto.Tempo, %{frame: :utc, resolution: :second}}}

    iex> Tempo.Ecto.Tempo.cast_type(resolution: :day)
    {:parameterized, {Tempo.Ecto.Tempo, %{frame: :utc, resolution: :day}}}

---

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