bitwalker / timex_ecto

An adapter for using Timex DateTimes with Ecto
MIT License
162 stars 68 forks source link

Different casting behaviour in timex_ecto 3 when trying to cast from a map #42

Closed jadlr closed 8 years ago

jadlr commented 8 years ago

Prior to timex_ecto 3 you could do:

iex(1)> Timex.Ecto.Date.cast(%{"day" => "15", "month" => "8", "year" => "2016"})
{:ok, #<Date(2016-08-15)>}

The same input will result in an error in timex_ecto 3:

iex(1)> Timex.Ecto.Date.cast(%{"day" => "15", "month" => "8", "year" => "2016"})
** (Protocol.UndefinedError) protocol Timex.Protocol not implemented for %{"day" => "15", "month" => "8", "year" => "2016"}
         (timex) lib/protocol.ex:1: Timex.Protocol.impl_for!/1
         (timex) lib/protocol.ex:30: Timex.Protocol.to_date/1
    (timex_ecto) lib/types/date.ex:28: Timex.Ecto.Date.cast/1

see https://github.com/bitwalker/timex_ecto/blob/3.0.3/lib/types/date.ex#L28

This is because Timex.to_date/1 is tried before Ecto.Date.cast/1. Is the new behaviour wanted or should it still be possible to cast from a string map?

jadlr commented 8 years ago

timex master now implements Timex.Protocol for maps. Should not be a problem in the future.