chrono icon indicating copy to clipboard operation
chrono copied to clipboard

Deserialize from string to `DateTime<Utc>`

Open kornelski opened this issue 3 years ago • 3 comments

serde::Deserialize is implemented for DateTime<FixedOffset>, but not for DateTime<Utc>.

This seems like an odd omission. It is inconvenient, because I prefer to use UTC dates exclusively in my application, but I can't use DateTime<Utc> in my structs (at least not without custom serde boilerplate or change of the serialized format from string to number).

Since DateTime<FixedOffset> can be trivially converted to DateTime<Utc>, I'd expect deserializing into DateTime<Utc> work exactly like deserializing into DateTime<FixedOffset> and then converting it to UTC.

kornelski avatar Oct 02 '22 22:10 kornelski

On a related note, chrono::serde module has functions for various numeric representations of dates, but not for rfc3339 and other string formats, so I can't use deserialize_with="rfc3339" on DateTime<Utc>.

kornelski avatar Oct 02 '22 22:10 kornelski

Seems reasonable to have a Deserialize impl for DateTime<Utc>. Would you be willing to contribute one?

djc avatar Oct 03 '22 10:10 djc

but not for rfc3339 and other string formats, so I can't use deserialize_with="rfc3339" on DateTime<Utc>.

Related to #544

conradludgate avatar Oct 15 '22 20:10 conradludgate