You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it would be good to add to_date_time, to_date, to_time and corresponding sigil_tsigil_d and sigil_(not_sure_yet) sigils that can be imported and would convert a regular Erlang timestamp to the appropriate Ecto type. I imagine you could do something like this to make it easy to use:
defmoduleMyApp.Factorydo# This would import the functions for use inside the factoryuseExMachina.Ecto,repo: MyRepo# I think this is nice because importing the sigils is optional so there are no accidental collisionsdefmacro__using__(_opts)doquotedoimportMyApp.Factory# Imports the sigils so you can them in your testsimportExMachina.TimeHelpersendendend# In a testuseMyApp.Factory# import the factory and the time helperscreate(:article,inserted_at: ~t(GoodTimes.a_day_ago))# GoodTimes generates erlang time stamps
The text was updated successfully, but these errors were encountered:
I believe I misunderstood the capabilities of sigils. For example
date_time=GoodTimes.a_day_ago~d(date_time)
Gets passed to sigil_d as {:<<>>, [line: 21], ["date_time"]} without any other information that would make it possible to figure out what date_time refers to. It could work with tuples and strings, but not variables like in that example.
So I think the sigil route is too limited to be that useful. We could make it work with strings, but I don't think that's super useful. I think it might be useful to have some shortcut functions like dt, t, and d cast to Ecto.DateTime, Ecto.Time and Ecto.Date respectively
I may delay this and wait for better date time support to become standard in Ecto now that Elixir will have native calendar types: elixir-lang/elixir#4383
See #54 for why this would be nice.
I think it would be good to add
to_date_time
,to_date
,to_time
and correspondingsigil_t
sigil_d
andsigil_(not_sure_yet)
sigils that can be imported and would convert a regular Erlang timestamp to the appropriate Ecto type. I imagine you could do something like this to make it easy to use:The text was updated successfully, but these errors were encountered: