Module nt_time::serde_with::iso_8601

source ·
Available on crate features serde and serde-human-readable only.
Expand description

Use the well-known ISO 8601 format when serializing and deserializing a FileTime.

Use this module in combination with Serde’s with attribute.

If the large-dates feature is not enabled, the maximum date and time is “9999-12-31 23:59:59.999999999 UTC”.

§Examples

use nt_time::{
    serde::{Deserialize, Serialize},
    serde_with::iso_8601,
    FileTime,
};

#[derive(Deserialize, Serialize)]
struct Time {
    #[serde(with = "iso_8601")]
    time: FileTime,
}

let ft = Time {
    time: FileTime::UNIX_EPOCH,
};
let json = serde_json::to_string(&ft).unwrap();
assert_eq!(json, r#"{"time":"+001970-01-01T00:00:00.000000000Z"}"#);

let ft: Time = serde_json::from_str(&json).unwrap();
assert_eq!(ft.time, FileTime::UNIX_EPOCH);

Modules§

Functions§