#![allow(clippy::unwrap_used, clippy::expect_used)]
use timeglyph::{format, interpret};
fn form(cands: &[interpret::Candidate], id: &str) -> String {
cands
.iter()
.find(|c| c.format_id == id)
.unwrap_or_else(|| panic!("no {id} candidate"))
.rendered
.clone()
.unwrap_or_default()
}
#[test]
fn modified_julian_day() {
let f = format("mjd").unwrap();
assert!(f
.decode_float(40587.0)
.unwrap()
.to_rfc3339()
.unwrap()
.starts_with("1970-01-01"));
assert!(f
.decode_float(51544.0)
.unwrap()
.to_rfc3339()
.unwrap()
.starts_with("2000-01-01"));
}
#[test]
fn mongodb_objectid() {
let c = interpret::interpret_string("5e0be1000000000000000000");
assert!(form(&c, "objectid").starts_with("2020-01-01"));
}
#[test]
fn uuid_version_7() {
let c = interpret::interpret_string("016f5e66-e800-7000-8000-000000000000");
assert!(form(&c, "uuid_v7").starts_with("2020-01-01"));
}
#[test]
fn uuid_version_6() {
let c = interpret::interpret_string("1ede857d-9302-66f0-8000-000000000000");
assert!(form(&c, "uuid_v6").starts_with("2023-05-01T19:39:12"));
}
#[test]
fn sql_server_datetime() {
let f = format("sqlserver").unwrap();
assert!(f
.decode_int(0)
.unwrap()
.to_rfc3339()
.unwrap()
.starts_with("1900-01-01"));
assert!(f
.decode_int(0xAB35_0000_0000)
.unwrap()
.to_rfc3339()
.unwrap()
.starts_with("2020-01-01"));
}
#[test]
fn iso_ordinal_and_week_dates() {
let o = interpret::interpret_string("2025-124");
assert!(form(&o, "iso_ordinal").starts_with("2025-05-04"));
let w = interpret::interpret_string("2025-W18-7");
assert!(form(&w, "iso_week").starts_with("2025-05-04"));
}