fix: cast embedded datetimes properly

This commit is contained in:
Zach Daniel 2022-09-22 02:59:40 -04:00
parent 479b09951c
commit d4a6feb589
3 changed files with 12 additions and 0 deletions

View file

@ -26,6 +26,10 @@ defmodule Ash.Type.NaiveDatetime do
@impl true
def cast_stored(nil, _), do: {:ok, nil}
def cast_stored(value, constraints) when is_binary(value) do
cast_input(value, constraints)
end
def cast_stored(value, _) do
Ecto.Type.load(:naive_datetime, value)
end

View file

@ -24,6 +24,10 @@ defmodule Ash.Type.UtcDatetime do
@impl true
def cast_stored(nil, _), do: {:ok, nil}
def cast_stored(value, constraints) when is_binary(value) do
cast_input(value, constraints)
end
def cast_stored(value, _) do
Ecto.Type.load(:utc_datetime, value)
end

View file

@ -24,6 +24,10 @@ defmodule Ash.Type.UtcDatetimeUsec do
@impl true
def cast_stored(nil, _), do: {:ok, nil}
def cast_stored(value, constraints) when is_binary(value) do
cast_input(value, constraints)
end
def cast_stored(value, _) do
case Ecto.Type.load(:utc_datetime_usec, value) do
{:ok, value} ->