Matt Beanland
AEAsh Elixir
•Created by Terris on 5/28/2025 in #today-i-learned
Comp is an Ash module for comparing stuff
Yes I understand it is based on Comparable protocol from https://hexdocs.pm/comparable/readme.html Comparable — Comparable v1.0.0
2 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
Have created https://github.com/ash-project/ash/issues/2022 and PR https://github.com/ash-project/ash/pull/2023
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
Thanks Zach, will do
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
I’m not sure it is explicit, looks accidental. It isn’t in the ash docs… I understand fixing it might be disruptive to those with ash in prod.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
Do you want me to raise a PR along these lines?
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
If the intent of existing types is to never have microseconds we should nerf the Calendar.microsecond struct in ash before the ecto cast or one day if someone fixes ecto to accept the elixir types completely rather than accidentally then ash users of these native types will still have zeroed microseconds in the database.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
OK, we should have naive_datetime_usec too.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
I’m building a datalayer to support Time, DateTime, etc so I need a solution for time with usec. I’m aware of utc_datetime_usec in Ash. I’m not sure why Ash.Type.Time, Ash.Type.DateTime and Ash.Type.NaiveDateTime are lossy when they are used to store corresponding Elixir types but I think this is wrong.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
One easy way to test it in ash is by modifying time_test.exs to inject/expect times with and without microseconds.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
I was just showing the issue with the cast
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
I’m not casting using Ecto, ash is in time.ex
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
I can PR ash if you like?
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
Ash time.ex can fix by converting time struct to map or tuple ahead of cast, decapsulating microsecond.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
Yes I named it above. The issue is with microsecond. In Ecto.Type.Time microsecond is an integer, in Elixir’s Time it is a Calender.microsecond struct, so ecto doesn’t cast it.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
It is actually the Ecto.Type.cast which is truncating the microseconds, for example iex(13)> time = Time.utc_now()
~T[09:53:47.984771]
iex(14)> Ecto.Type.cast(:time, time)
{:ok, ~T[09:53:47]}
iex(15)> {:ok, ecto_time} = Ecto.Type.cast(:time, time)
{:ok, ~T[09:53:47]}
iex(16)> ecto_time
~T[09:53:47]
iex(17)> time == ecto_time
false
iex(18)> time |> Map.from_struct()
%{
microsecond: {984771, 6},
second: 47,
calendar: Calendar.ISO,
minute: 53,
hour: 9
}
iex(19)> ecto_time |> Map.from_struct()
%{microsecond: {0, 0}, second: 47, calendar: Calendar.ISO, minute: 53, hour: 9}
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds

42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
It is comparing the injected and returned property values
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
The failing test is in ash_neo4j_test.exs and is “type node can be created using ash with properties”
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
There is a single test case that is failing, it is showing that ash create (where I inject a time property defined as above) is truncating the time / date_time and naive_datetime values in the Test.Type resource to whole seconds, actually in the changeset rather than the create.
42 replies
AEAsh Elixir
•Created by Matt Beanland on 5/9/2025 in #support
Changeset truncates Time, DateTime and NaiveDateTime to whole seconds
Yes I've got a failed test on ash_neo4j on the 9-property-types branch https://github.com/diffo-dev/ash_neo4j/tree/9-property-types
42 replies