NaiveDateTime.from_iso8601/2

Hello everyone.

I have a question about NaiveDateTime module from_iso8601/2 function.

This function will parse string datetimes like 2019-05-23 13:36:26.287939 to NaiveDateTime. The second argument is the calendar (which is set to Calendar.ISO by default).

Say i have a string datetime in another calendar like 1398-05-21 10:03:04. If i call from_iso8601 it will first parse the string and then convert it from ISO to my calendar.

NaiveDateTime.from_iso8601("1398-01-23 23:50:07", Jalaali.Calendar)
{:ok,
 %NaiveDateTime{
   calendar: Jalaali.Calendar,
   day: 4,
   hour: 23,
   microsecond: {0, 0},
   minute: 50,
   month: 11,
   second: 7,
   year: 776
 }}

I think it should parse the string datetime and inject the calendar into the NaiveDateTime struct.

Expected

NaiveDateTime.from_iso8601("1398-01-23 23:50:07", Jalaali.Calendar)
{:ok,
 %NaiveDateTime{
  calendar: Jalaali.Calendar,
  day: 31,
  hour: 23,
  microsecond: {0, 0},
  minute: 50,
  month: 1,
  second: 7,
  year: 1398
}}

Note that the DateTime module has a DateTime.from_iso8601/2 function which will parse the DateTime and then injects the calendar module into the datetime.

In other words, DateTime.from_iso8601/2 works OK but NaiveDateTime.from_iso8601/2 is not. Is this a bug or naive datetime is always considered as ISO?

@josevalim can you please take a look?

Related: elixir-jalaali #10

My expectation would be the opposite - i.e. the bug is in DateTime.from_iso8601/2.

ISO8601 is standardized on the Gregorian calendar, so from_iso8601 would only expect a Gregorian date in the string - not a string from another calendar. Once the Gregorian date is fully parsed it is converted to the target calendar (Date.from_iso8601/2 also works in this manner).