Files
sx/examples/1629-std-time.sx
agra da2f76b383 feat: std.time — wall + monotonic clocks over clock_gettime (PLAN-HTTPZ S1)
now_secs (CLOCK_REALTIME, epoch seconds) and mono_ms (CLOCK_MONOTONIC,
process-local milliseconds for deadlines). Clock ids are darwin's; the
per-OS selection mechanism is PLAN-HTTPZ C3. No error channel: with
module-constant clock ids and a stack timespec, clock_gettime is total.
std.sx namespace tail carries the time alias; examples/1629 pins epoch
plausibility, monotone advance, and the alias carry.
2026-06-12 20:33:01 +03:00

36 lines
1006 B
Plaintext

// std.time (PLAN-HTTPZ S1): the wall clock reads a plausible epoch and
// the monotonic clock advances and never runs backwards. The `time`
// alias rides the std.sx namespace tail like its siblings.
#import "modules/std.sx";
main :: () -> i32 {
now := time.now_secs();
if now < 1767225600 { // before 2026-01-01: implausible
print("wall clock implausibly old: {}\n", now);
return 1;
}
if now > 4102444800 { // after 2100-01-01: implausible
print("wall clock implausibly far: {}\n", now);
return 1;
}
a := time.mono_ms();
b := a;
spins := 0;
while b == a and spins < 100000000 { // a real ms tick arrives long before the bound
b = time.mono_ms();
spins += 1;
}
if b < a {
print("monotonic went backwards: {} -> {}\n", a, b);
return 1;
}
if b == a {
print("monotonic never advanced\n");
return 1;
}
print("std.time ok\n");
return 0;
}