pub fn deserialize<'de, D>(d: D) -> Result<Option<NaiveDateTime>, D::Error>where
    D: Deserializer<'de>,
Expand description

Deserialize a NaiveDateTime from a nanosecond timestamp or none

Intended for use with serdes deserialize_with attribute.

Example:

use chrono::naive::serde::ts_nanoseconds_option::deserialize as from_nano_tsopt;
#[derive(Debug, PartialEq, Deserialize)]
struct S {
    #[serde(deserialize_with = "from_nano_tsopt")]
    time: Option<NaiveDateTime>
}

let my_s: S = serde_json::from_str(r#"{ "time": 1526522699918355733 }"#)?;
assert_eq!(my_s, S { time: NaiveDateTime::from_timestamp_opt(1526522699, 918355733) });