atproto pds in zig pds.zat.dev
pds atproto
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637const std = @import("std");const Io = std.Io;
var configured_io: ?Io = null;
pub fn init(io: Io) void { configured_io = io;}
fn currentIo() Io { return configured_io orelse std.Options.debug_io;}
pub fn nowNanos() i96 { return Io.Timestamp.now(currentIo(), .real).nanoseconds;}
/// nanoseconds on the suspend-excluding monotonic clock; for durations onlypub fn monotonicNs() u64 { return @intCast(@max(0, Io.Timestamp.now(currentIo(), .awake).nanoseconds));}
pub fn nowMs() i64 { return @intCast(@divTrunc(nowNanos(), std.time.ns_per_ms));}
pub fn nowSeconds() i64 { return @intCast(@divTrunc(nowNanos(), std.time.ns_per_s));}
test "clock runs without init and is monotone-ish across calls" { const a = nowSeconds(); const b = nowMs(); try std.testing.expect(a > 1_700_000_000); try std.testing.expect(@divTrunc(b, 1000) >= a);}