timex_ecto v3.4.0 Timex.Ecto.Date

Support for using Timex with :date fields

Link to this section Summary

Functions

Handle casting to Timex.Ecto.Date

Convert to native Ecto representation

Creates a Timex.Date from from a passed in date.

Returns the underlying schema type for the custom type.

Link to this section Functions

Link to this function

autogenerate(precision \\ :sec)

Handle casting to Timex.Ecto.Date

Convert to native Ecto representation

Creates a Timex.Date from from a passed in date.

Returns {:ok, Timex.Date} when successful.

Returns :error if the type passed in is either not an erl date nor Ecto.Date

Examples

Using an Ecto.Date:

iex> Ecto.Date.from_erl({2017, 2, 1})
...> |> Timex.Ecto.Date.load
{:ok, ~D[2017-02-01]}

Using an erl date:

iex> Timex.Ecto.Date.load({2017, 2, 1})
{:ok, ~D[2017-02-01]}

Returns the underlying schema type for the custom type.

For example, if you want to provide your own date structures, the type function should return :date.

Note this function is not required to return Ecto primitive types, the type is only required to be known by the adapter.

Callback implementation for Ecto.Type.type/0.