We have `Date.to_iso8601`, `Date.from_iso8601`, `Time.to_iso8601`, 
`Time.from_iso8601`, and `DateTime.to_iso8601` functions, but we do not 
have a `DateTime.from_iso8601` function.

Congruence led me to believe that this function *had to* exist somewhere, 
so I spent a significant amount of time searching and confirming that it 
was indeed missing.

I assumed that there must be a good reason for it to be missing, so I 
searched the issue tracker, this mailing list, and eventually asked in IRC. 
Here's a link to the transcript of that discussion, for context: 
https://botbot.me/freenode/elixir-lang/2016-11-28/?msg=77118328&page=6

In short, it was suggested that conversion from ISO8601 to DateTime format 
was ambiguous, since there is no concrete time zone encoded in the ISO8601 
format, and the DateTime struct, expects one.

However, we do have "generic" time zone codes that could be used to convey 
the situation of "I know the UTC offset, but I don't know anything else 
about the time zone". According to wikipedia 
<https://en.wikipedia.org/wiki/List_of_tz_database_time_zones>, the IANA tz 
database defines the "Etc" area, and codes like "Etc/GMT+3" for this kind 
of situation.  This seems to be the approach that the `timex` library uses 
when parsing formats that only know the UTC offset.

For whatever it's worth, Ruby's `Time.parse` method uses `nil` for the time 
zone code when it is not known, and relies on only having `utc_offset` 
defined, so we could also do something similar to that.

In general, I'd argue that having bidirectional conversions for `DateTime` 
(or no conversion at all) is the best way to violate the "principle of 
least surprise", especially when bidirectional transformations are 
implemented for `Date` and `Time` to/from ISO8601.

Is there another reason to exclude this function?  If so, we should at the 
very least have the reasoning on record so that users who run into the same 
question can answer it by searching instead of asking again.

Thanks,

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/045df69b-9ed1-48b8-8344-76a9924b9b8a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to