iddm / serde-aux

An auxiliary serde library providing helpful functions for serialisation and deserialisation for containers, struct fields and others.
MIT License
152 stars 26 forks source link

Please add deserialize_datetime_utc_from_seconds #27

Closed Lurk closed 1 year ago

Lurk commented 1 year ago

It is almost a copy of deserialize_datetime_utc_from_milliseconds, but I found myself implementing it over and over.

#[cfg(feature = "chrono")]
pub fn deserialize_datetime_utc_from_seconds<'de, D>(
    deserializer: D,
) -> Result<chrono::DateTime<chrono::Utc>, D::Error>
where
    D: Deserializer<'de>,
{
    let number = deserialize_number_from_string::<i64, D>(deserializer)?;

    Ok(DateTime::<Utc>::from_utc(
        NaiveDateTime::from_timestamp(number, 0),
        Utc,
    ))
}

I will make a pull request if needed. Thank you

iddm commented 1 year ago

I am sorry, I somehow overlooked this issue having been created. Thank you for your awesome contribution, this looks like a nice thing to have in our collection. I'd surely approve if it were here. I'll add it myself this weekend. Feel free to ping me should I forget to do this.

iddm commented 1 year ago

I'll publish the new version later this evening.

iddm commented 1 year ago

Sorry, yesterday evening I got pretty busy. I have just published it as 4.1.0.

Lurk commented 1 year ago

Yey! Thank for the amazing crate :)