Pattern matching against Dates in Elixir
Dates in Elixir aren't native values, so there aren't any guard clause functions available for use with date/datetime. You can, however, use pattern matching:
def foo(%Date{} = date) do
Timex.to_naive_datetime(date) |> foo
end
def foo(%DateTime{} = datetime) do
Timex.to_naive_datetime(datetime) |> foo
end
def foo(%NaiveDateTime{} = datetime) do
IO.inspect({"My Naive Datetime", datetime})
end
Tweet