DateTime.from_iso8601 can not read basic format produced by DateTime.to_iso8601

I get some DateTime strings I wanted to parse.
DateTime looks quite nice for such things but somehow it can produce the datetime strings in the exact same format but it can not parse them.
I was expecting it can at least parse what it can produce

datetime = DateTime.utc_now
datetime_basic_string = DateTime.to_iso8601(datetime, :basic)
#sadly results in {:error, :invalid_format}
1 Like

Like the documentation for DateTime.from_iso8601/2 says (emphasis mine),

Parses the extended “Date and time of day” format described by ISO 8601:2004.

It currently does not even try to parse the “basic” version.

1 Like

I do not say the documentation does not match the behaviour. I say the behaviour is unexpected and does not make sense.
If it can produce it parsing should also be possible.
Its a missing feature if you want it that way

1 Like

True, it would be more consistent if it would work both ways (:basic and :extended).
Well, you should do the PR then. As your change makes sense and does not harm the existing API, should be accepted!

1 Like