How Phoenix do to convert 5 select to a datetime

Phoenix form contains a datetime field. Which output 5 select.
I don’t like the 5 select thing, and I’d like to use a date and a time fields.
The thing I don’t understand is how Phoenix convert the map %{year:"",month:"",day:"",hour:"",min:""} to a ecto datetime.
I assume it happens in the ecto.cast function. But I’m not sure and i didn’t find any reference. Can anybody give me a hint on this one.

1 Like

Actually Ecto.DateTime.cast/1 take in this case map like this (just :minute instead of :min and it simply cast it.

Eg.

map = %{day: 12, hour: 8, minute: 23, month: 10, year: 2014}
iex(2)> Ecto.DateTime.cast(map)
{:ok, #Ecto.DateTime<2014-10-12 08:23:00>}

My model contains this

field: :date, Ecto.Datetime

And my template contains this

<%=datetime_select(f, :date)%>

I edited my answer. Simply:
h Ecto.DateTime.cast/1 :slight_smile:

Ok, where is I call triggered ??

What I’d like to do is insert my own conversion function inside this process in order to convert a map %{date:"", time:""} to a real datetime