chronotope / chrono

Date and time library for Rust
Other
3.25k stars 515 forks source link

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

Open drozdziak1 opened 6 years ago

drozdziak1 commented 6 years ago

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

quodlibetor commented 6 years ago

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.

dermetfan commented 5 years ago

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.

quodlibetor commented 5 years ago

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.

Plecra commented 3 years ago

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