Misleading error in NaiveDateTime.to_iso8601

iex(14)> today = Date.utc_today()
iex(15)> now = Time.utc_now()    
iex(16)> naive = NaiveDateTime.new(today, now)
{:ok, ~N[2018-02-22 10:40:25.547910]}
iex(17)> NaiveDateTime.to_iso8601(naive)
** (ArgumentError) NaiveDateTime.to_iso8601/2 expects format to be :extended or :basic, got: :extended
    (elixir) lib/calendar/naive_datetime.ex:567: NaiveDateTime.to_iso8601/2

The problem is obviously that I’m sending tuple {:ok, datetieme} instead of just datetime to NaiveDateTime.to_iso8601 but the error indicates that problem is somewhere else.

And although I would like to send a PR, i really don’t know how to fix it :confused:
Here’s code in source: https://github.com/elixir-lang/elixir/blob/2d4be9850b04ded001d73464c66c04ffcd00bcce/lib/elixir/lib/calendar/naive_datetime.ex#L551

Anyone has clue how to fix the error message from elixir?

This has been fixed in 1.5.2 for DateTime: https://github.com/elixir-lang/elixir/issues/6503

The fix for NaiveDateTime is in Elixir master: https://github.com/elixir-lang/elixir/pull/7297

So it will probably be released in a version soon.


Damn, should have do my research properly :sweat_smile:

PS. How can I mark @Nicd answer as solved?

Marking as answered is only enabled in the “questions” categories, I’ve moved the thread and marked it accordingly :slight_smile:

1 Like