chrono icon indicating copy to clipboard operation
chrono copied to clipboard

ISO 8601 times without separators (`YMD\Thms\Z`) are not understood by serde_json

Open drozdziak1 opened this issue 7 years ago • 4 comments

Like in the subject, if I attempt to deserialize a JSON with a time like 20180505T214800Z into a struct that derives Deserialize and wants to keep it in a DateTime<Utc> field, it's not working unless I add all - and : separators. Maybe there's a way to specify a format in-field?

BTW I'm open to contributing this myself, if I were to add this format to chrono deserialization parsers, where would I do it?

Thanks, Stan

drozdziak1 avatar May 05 '18 19:05 drozdziak1

Chrono serialization/deserialization should be done using serde's with annotation. The ts_seconds module is an example of what it should look like. The docs show example usage.

I don't believe that this is a common enough format that we should support it directly in chrono, but anything we can do to make external implementations of this kind of thing easier (either via docs or via helper functions) would be most welcome.

quodlibetor avatar May 08 '18 19:05 quodlibetor

I don't want to be a smart-ass but this format is actually valid. See annex B.1.3 in the ISO 8601:2004 standard:

Basic format Extended format
19850412T101530 1985-04-12T10:15:30

Since chrono claims to strictly adhere to ISO 8601 I think this should be supported out of the box.

dermetfan avatar Sep 06 '18 20:09 dermetfan

Chrono doesn't claim to be strictly iso8601 compliant, in essentially all places we have the option we prefer rfc3339.

Making the default deserializer try the number of fallbacks that would be required to support every iso 8601 format out of the box is extremely unlikely to be possible with the kind of default performance we like to have.

quodlibetor avatar Sep 06 '18 22:09 quodlibetor

https://github.com/chronotope/chrono/blame/3467172c31188006147585f6ed3727629d642fed/README.md#L22

Chrono strictly adheres to ISO 8601.

I think it's fair to expect chrono to be able to parse iso 8601 dates

Plecra avatar Mar 22 '21 15:03 Plecra