Create a gist now

Instantly share code, notes, and snippets.

@caike /datetime.exs
Last active Aug 16, 2016

What would you like to do?
Elixir. Example of a function with a default argument value set to the current DateTime - calculated on runtime.
defmodule CreditCard do
def current_amount_due(charges, apr, due_date, current_date \\ date_now()) do
current_date
# then proceed with calculation..
end
defp date_now do
DateTime.utc_now |> DateTime.to_unix
end
end
IO.inspect CreditCard.current_amount_due([100_00], 0.15, true)
:timer.sleep(2000)
IO.inspect CreditCard.current_amount_due([100_00], 0.15, false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment