#![allow(clippy::unwrap_used, clippy::expect_used)]
use std::process::Command;
#[test]
fn filetime_hilo_reconstructs_the_64bit_filetime() {
let inst = timeglyph::compose::filetime_hilo(0x6905_0000, 0x01d5_c036).unwrap();
assert_eq!(
inst.render(&timeglyph::RenderZone::Utc).unwrap(),
"2020-01-01T00:00:00Z"
);
}
#[test]
fn filetime_hilo_agrees_with_time_decode() {
let ok = Command::new("time-decode")
.arg("--version")
.output()
.is_ok_and(|o| o.status.success());
if !ok {
eprintln!("skipping: time-decode not on PATH");
return;
}
let out = Command::new("time-decode")
.args(["--filetimelohi", "69050000:01d5c036"])
.output()
.unwrap();
let text = String::from_utf8_lossy(&out.stdout);
assert!(text.contains("2020-01-01 00:00:00"), "oracle: {text}");
let inst = timeglyph::compose::filetime_hilo(0x6905_0000, 0x01d5_c036).unwrap();
assert!(inst
.render(&timeglyph::RenderZone::Utc)
.unwrap()
.starts_with("2020-01-01T00:00:00"));
}
#[test]
fn filetime_hilo_out_of_range_errs_not_panics() {
assert!(timeglyph::compose::filetime_hilo(0xffff_ffff, 0xffff_ffff).is_err());
}
#[test]
fn unix_sec_nsec_reconstructs_a_timespec() {
let inst = timeglyph::compose::unix_sec_nsec(1_577_836_800, 500_000_000);
assert!(inst
.render(&timeglyph::RenderZone::Utc)
.unwrap()
.starts_with("2020-01-01T00:00:00.5"));
}
#[test]
fn relative_adds_a_duration_to_an_anchor() {
let anchor = timeglyph::compose::unix_sec_nsec(1_577_836_800, 0);
let inst = timeglyph::compose::relative(anchor, 3_600_000, timeglyph::Unit::Millis);
assert_eq!(
inst.render(&timeglyph::RenderZone::Utc).unwrap(),
"2020-01-01T01:00:00Z"
);
}
#[cfg(feature = "leap")]
#[test]
fn gps_week_tow_resolves_leap_correct_utc() {
let r = timeglyph::compose::gps_week_tow(2000, 0.0);
assert!(r.utc_rfc3339.starts_with("2018-05-05T23:59:42"), "{r:?}");
}
#[test]
fn vmsd_reconstructs_vmware_snapshot_micros() {
let inst = timeglyph::compose::vmsd(367_368, -1_040_564_224);
assert_eq!(
inst.render(&timeglyph::RenderZone::Utc).unwrap(),
"2020-01-01T00:00:00Z"
);
}