#![forbid(unsafe_code)]
use clock_kit::{Clock, SystemClock, Timestamp, WallTime};
#[test]
fn wall_and_mono_independent_no_implicit_conversion() {
let t = Timestamp::from_parts(WallTime::from_unix_nanos(1_000), 7);
assert_eq!(t.wall.unix_nanos(), 1_000);
assert_eq!(t.mono, 7);
assert_ne!(t.wall.unix_nanos(), t.mono);
assert_eq!(t.mono_from_wall_lossy(), 1_000);
assert_eq!(WallTime::default(), WallTime::UNIX_EPOCH);
assert_eq!(WallTime::UNIX_EPOCH.unix_nanos(), 0);
}
#[cfg(feature = "std")]
#[test]
fn wall_is_systemtime_backed_under_std() {
use std::time::{Duration, SystemTime};
let wall = WallTime::from_unix_nanos(1_234_567_890);
let exact = matches!(
wall.system().duration_since(SystemTime::UNIX_EPOCH),
Ok(d) if d.as_nanos() == 1_234_567_890
);
assert!(exact, "system() round trip must preserve epoch nanos");
let past = SystemTime::UNIX_EPOCH.checked_sub(Duration::from_secs(1));
if let Some(past) = past {
assert_eq!(
WallTime::from_unix_nanos(0),
clock_kit::timestamp::WallTime::from_unix_nanos(0)
);
let _ = past; }
let clock = SystemClock::new();
let t = clock.now();
let rebuilt = t.wall.system();
let nanos = rebuilt
.duration_since(SystemTime::UNIX_EPOCH)
.map_or(0, |d| u64::try_from(d.as_nanos()).unwrap_or(u64::MAX));
assert_eq!(nanos, t.wall.unix_nanos());
}
#[test]
fn system_reading_has_both_independent_fields() {
let clock = SystemClock::new();
let a = clock.now();
let b = clock.now();
assert!(b.mono >= a.mono);
assert!(a.wall.unix_nanos() > 0 || a.mono == 0);
}