makepad/libs/relax/compiler/tests/std/os_time.rs
Admin b22a714840 makepad run: the Rust JIT (libs/relax) and makepad-remote
The JIT that runs makepad apps from source: lexer, front end, type checker,
lazy borrow checker (Gandalf; `--check-first` opts in), codegen, session and
warm/cold caches keyed by compiler stamp, provided crates bound late,
startup images, live patching. User-facing name is `makepad run` (binary
`makepad`, MAKEPAD_RUN_* env, ~/.makepad-run); libs/relax stays the internal
library name. `makepad check` reports rustc-style diagnostics with rustc
error codes and checks a whole workspace (`--workspace`). Runs on macOS,
Linux, Windows and Android. makepad-remote: one tool schema for apps and the
WM (app/1): grabs, captures, traces, frame profiles and tweaks.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-13 12:26:21 +02:00

31 lines
1.5 KiB
Rust

// std-os lane: std::time Instant / SystemTime (differential: os_diff.sh)
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
#[test]
fn a01_instant() {
let a = Instant::now();
let b = Instant::now();
println!("| {} {}", b >= a, (b - a) < Duration::from_secs(1));
println!("| {:?} {:?}", a.checked_duration_since(b + Duration::from_secs(1)), (a + Duration::from_millis(5)).duration_since(a));
println!("| {:?}", a.saturating_duration_since(a + Duration::from_secs(3)));
println!("| {} {}", a.checked_add(Duration::MAX).is_none(), a.checked_sub(Duration::from_secs(1)).is_some());
let mut c = a;
c += Duration::from_millis(1500);
c -= Duration::from_millis(500);
println!("| {:?} {}", c - a, a.elapsed() < Duration::from_secs(5));
}
#[test]
fn a02_system_time() {
let now = SystemTime::now();
let since = now.duration_since(UNIX_EPOCH).unwrap();
println!("| {}", since.as_secs() > 1_700_000_000);
let e = UNIX_EPOCH.duration_since(now).unwrap_err();
println!("| {} {}", e, e.duration() == since);
let t = UNIX_EPOCH + Duration::new(1234, 5678);
println!("| {:?} {:?}", t.duration_since(UNIX_EPOCH), t);
println!("| {:?} {:?}", UNIX_EPOCH, SystemTime::UNIX_EPOCH == UNIX_EPOCH);
println!("| {:?}", (t - Duration::from_secs(2000)).duration_since(UNIX_EPOCH));
println!("| {:?}", t.checked_sub(Duration::new(1234, 5679)).map(|x| x < UNIX_EPOCH));
println!("| {}", now.elapsed().unwrap() < Duration::from_secs(5));
}