chronotope / chrono

Date and time library for Rust
Other
3.22k stars 512 forks source link

Deserialize from string to `DateTime<Utc>` #833

Open kornelski opened 1 year ago

kornelski commented 1 year ago

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 commented 1 year ago

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>.

djc commented 1 year ago

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

conradludgate commented 1 year ago

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

Related to #544