Tempo.Ecto.Tempo (Tempo SQL v0.1.0)

View Source

Ecto.ParameterizedType for persisting a bare Tempo.t/0 as a PostgreSQL tstzrange.

A bare Tempo value is an implicit span — ~o"2026Y" spans the whole of 2026, ~o"2026Y-06M" spans June 2026. This type materialises the implicit span via Tempo.to_interval/1 and then delegates to Tempo.Ecto.Interval.

Usage

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

Options

  • :resolution — same as Tempo.Ecto.Interval. With :year, loaded values come back as year-resolution Tempos (the closest shape-preserving round-trip available for implicit spans).

Round-trip caveat

Implicit spans do not round-trip as implicit spans without help. A stored ~o"2026Y" loads back as a %Tempo.Interval{} — there is no way to recover "it was just a year token" from a tstzrange alone. Setting resolution: :year gives the closest approximation by returning an interval whose endpoints are year-resolution Tempos. See the storage contract guide.

Tempo values that materialise to an IntervalSet (any value with a recurrence rule) are rejected — use a Tempo.Ecto.IntervalSet column instead.

Summary

Functions

cast_type(options \\ [])

See Tempo.Ecto.Interval.cast_type/1.