-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable DateTime types #2
base: master
Are you sure you want to change the base?
Conversation
… / :naive_datetime)
hey @narrowtux thanks for your PR. I'll take a look as soon as possible. |
@narrowtux thanks you for your PR. We'll take a look ASAP. |
@narrowtux also, I think it's missing some tests, especially related to Schema. |
@@ -254,7 +254,8 @@ defmodule Coherence.Schema do | |||
|
|||
Returns a changeset ready for Repo.update | |||
""" | |||
def lock(user, locked_at \\ NaiveDateTime.utc_now()) do | |||
def lock(user, locked_at \\ nil) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use Config.datetime_module().utc_now()
as a default param?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that default parameters are decided at compile time - then all locked users would have the same locked_at date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I got this wrong - this suggests that the expression is only evaluated when needed: https://elixir-lang.org/getting-started/modules-and-functions.html#default-arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, look:
defmodule MarsRover do
def time(foo \\ NaiveDateTime.utc_now()) do
foo
end
end
iex [1] > MarsRover.time
~N[2019-06-20 13:58:51.149503]
iex [2] > MarsRover.time
~N[2019-06-20 13:58:52.923541]
iex [3] >
Again, thank you! <3
This PR adds the possibility to configure the DateTime module used to generate
utc_now()
datetimes and the types of all datetime fields in the user schema.config.exs
user.ex