Date/time library
See also the [dtg] crate.
``` use chrono::{TimeZone, Utc}; use dtg_lib::{tz, Dtg, Format};
let epoch = 1658448142; let nanoseconds = 936196858; let x = "Xg6L02M"; let rfc3339 = "2022-07-22T00:02:22Z"; let dayofweekutc = "Friday"; let dayofweek_mt = "Thursday";
let dtg1str = format!("{}", epoch); let dtg2str = format!("{}.{}", epoch, nanoseconds);
let dtg1ts = Dtg::from(&dtg1str).unwrap(); let dtg1dt = Dtg::fromdt(&Utc.timestamp(epoch, 0)); let dtg1x = Dtg::fromx(x).unwrap();
asserteq!(dtg1ts, dtg1dt); asserteq!(dtg1dt, dtg1x); asserteq!(dtg1x, dtg1_ts);
let dtg2ts = Dtg::from(&dtg2str).unwrap(); let dtg2dt = Dtg::from_dt(&Utc.timestamp(epoch, nanoseconds));
asserteq!(dtg2ts, dtg2_dt);
asserteq!(dtg1ts.rfc3339(), rfc3339); asserteq!(dtg1ts.format(&None, &None), rfc3339); asserteq!(dtg1ts.format(&Some(Format::X), &None), x);
let dayofweekfmt = Some(Format::Custom(String::from("%A"))); let tzmt = tz("MST7MDT").ok();
asserteq!(dtg1ts.format(&dayofweekfmt, &None), dayofweekutc); asserteq!(dtg1ts.format(&dayofweekfmt, &tzmt), dayofweek_mt); ```