Misleading error in NaiveDateTime.to_iso8601

iex(14)> today = Date.utc_today()
~D[2018-02-22]
iex(15)> now = Time.utc_now()    
~T[10:40:25.547910]
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: elixir/lib/elixir/lib/calendar/naive_datetime.ex at 2d4be9850b04ded001d73464c66c04ffcd00bcce · elixir-lang/elixir · GitHub

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

This has been fixed in 1.5.2 for DateTime: Improve error handling for DateTime.to_iso8601 · Issue #6503 · elixir-lang/elixir · GitHub

The fix for NaiveDateTime is in Elixir master: Unify *.to_iso8601 functions for calendar types by michalmuskala · Pull Request #7297 · elixir-lang/elixir · GitHub

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: