View Source Ecto.UTCTimeRange (Ecto DateTimeRange v0.99.0)
An Ecto.Type
wrapping a :tstzrange
Postgres column. To the application, it appears as
a struct with :start_at
and :end_at
, with :time
values.
Deprecated
This module is deprecated in favor of
Ecto.DateTimeRange.Time
.
defmodule Core.Thing do
use Ecto.Schema
import Ecto.Changeset
schema "things" do
field :performed_during, Ecto.UTCTimeRange
end
@required_attrs ~w[performed_during]a
def changeset(data \ %__MODULE__{}, attrs) do
data
|> cast(attrs, @required_attrs)
|> validate_required(@required_attrs)
end
end
Link to this section Summary
Ecto.Type Callbacks
Converts user-provided data (for example from a form) to the Elixir term.
Converts the Elixir term to the Ecto native type.
Declares than when used in embedded schemas, the type will be dumped before being encoded.
Checks if two terms are equal.
Converts the Ecto native type to the Elixir term.
Declares the native type that will be used in the database.
Functions
Returns true or false depending on whether the time is falls within the specified range.
Create an Ecto.UTCDateTimeRange
from two ISO8601 strings.
Link to this section Types
Link to this section Ecto.Type Callbacks
Converts user-provided data (for example from a form) to the Elixir term.
Converts the Elixir term to the Ecto native type.
Declares than when used in embedded schemas, the type will be dumped before being encoded.
Checks if two terms are equal.
Converts the Ecto native type to the Elixir term.
Declares the native type that will be used in the database.
Link to this section Functions
Returns true or false depending on whether the time is falls within the specified range.
example
Example
iex> import Ecto.DateTimeRange
...>
iex> Ecto.UTCTimeRange.contains?(~t[01:00:00..02:00:00]T, ~T[00:00:00])
false
iex> Ecto.UTCTimeRange.contains?(~t[01:00:00..02:00:00]T, ~T[01:00:00])
true
iex> Ecto.UTCTimeRange.contains?(~t[01:00:00..02:00:00]T, ~T[01:59:59])
true
iex> Ecto.UTCTimeRange.contains?(~t[01:00:00..02:00:00]T, ~T[02:00:00])
false
Create an Ecto.UTCDateTimeRange
from two ISO8601 strings.
example
Example
iex> Ecto.UTCTimeRange.parse("00:01:00Z..00:01:01Z")
{:ok, %Ecto.UTCTimeRange{start_at: ~T[00:01:00Z], end_at: ~T[00:01:01Z]}}
iex> Ecto.UTCTimeRange.parse("00:01:00Z..later")
{:error, "Unable to parse Time(s) from input"}