diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-04 23:56:05 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:02:08 -0300 |
| commit | 98d22582eb7305973925f3e014bde3549320fee0 (patch) | |
| tree | 31e532bd4d6c4b59ef7811cf03150e722d20ea31 | |
| parent | 53c8d3d4c3c9673c0070eceb652326193fb32012 (diff) | |
| download | pardes-98d22582eb7305973925f3e014bde3549320fee0.tar.gz pardes-98d22582eb7305973925f3e014bde3549320fee0.zip | |
Messages: a clock's text is one function, Message.clockText(seconds, gmtoff), which the message stamp (with localtime_r's offset) and the tape's guessed clock both call where each wrote its own, and PARDES_NOTIME is read in one place, Message.noTime, which lsp_client's hideTime asks
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
| -rw-r--r-- | src/Messages.zig | 32 | ||||
| -rw-r--r-- | src/lsp/lsp_client.zig | 3 | ||||
| -rw-r--r-- | src/tape.zig | 9 |
3 files changed, 22 insertions, 22 deletions
diff --git a/src/Messages.zig b/src/Messages.zig index 891caf77..63650be5 100644 --- a/src/Messages.zig +++ b/src/Messages.zig @@ -105,22 +105,30 @@ pub const Message = struct { }; extern "c" fn localtime_r(timep: *const libc.time_t, result: *Tm) ?*Tm; + /// PARDES_NOTIME set (the tests, a snapshot run): every clock reads + /// `--:--:--`. + pub fn noTime() bool { + const v = libc.getenv("PARDES_NOTIME") orelse return false; + return std.mem.span(v).len != 0; + } + + /// `HH:MM:SS` of `seconds` since the epoch in a zone `gmtoff` seconds + /// east of UTC: the message row's time of day, and a replica's guess + /// of the session's (src/tape.zig). + pub fn clockText(seconds: i64, gmtoff: i64) [8]u8 { + var text: [8]u8 = "--:--:--".*; + if (noTime()) return text; + const day: u32 = @intCast(@mod(seconds + gmtoff, 86400)); + _ = std.fmt.bufPrint(&text, "{d:0>2}:{d:0>2}:{d:0>2}", .{ day / 3600, day / 60 % 60, day % 60 }) catch {}; + return text; + } + fn timeOfDay() [8]u8 { - var clock: [8]u8 = "--:--:--".*; - const notime = if (libc.getenv("PARDES_NOTIME")) |v| std.mem.span(v).len != 0 else false; - if (notime) return clock; var ts: libc.timespec = undefined; _ = libc.clock_gettime(.REALTIME, &ts); - const secs: libc.time_t = ts.sec; var tm: Tm = undefined; - if (localtime_r(&secs, &tm) != null) { - _ = std.fmt.bufPrint(&clock, "{d:0>2}:{d:0>2}:{d:0>2}", .{ - @as(u32, @intCast(tm.hour)), - @as(u32, @intCast(tm.min)), - @as(u32, @intCast(tm.sec)), - }) catch {}; - } - return clock; + if (localtime_r(&ts.sec, &tm) == null) return "--:--:--".*; + return clockText(ts.sec, tm.gmtoff); } pub fn body(text: []const u8) []const u8 { diff --git a/src/lsp/lsp_client.zig b/src/lsp/lsp_client.zig index e685aa7d..94d5bded 100644 --- a/src/lsp/lsp_client.zig +++ b/src/lsp/lsp_client.zig @@ -392,8 +392,7 @@ fn record(si: usize, req: lsp.Req, us: u64, rows: usize, err: []const u8) void { } fn hideTime() bool { - const v = libc.getenv("PARDES_NOTIME") orelse return false; - return std.mem.span(v).len != 0; + return @import("../Messages.zig").Message.noTime(); } /// `SPC l w` narration, threaded through the real path, so it cannot diff --git a/src/tape.zig b/src/tape.zig index 78b3c34b..29b1197d 100644 --- a/src/tape.zig +++ b/src/tape.zig @@ -949,14 +949,7 @@ pub const Guess = struct { real_ns: i64, mono_ns: i64, gmtoff: i32 }; fn guessed(comptime R: type, g: Guess) R { if (R == u32) return std.math.cast(u32, @divFloor(g.real_ns, std.time.ns_per_s)) orelse 0; if (R == i64) return @divFloor(g.mono_ns, std.time.ns_per_ms); - if (R == [8]u8) { - var clock: [8]u8 = "--:--:--".*; - const notime = if (libc.getenv("PARDES_NOTIME")) |v| std.mem.span(v).len != 0 else false; - if (notime) return clock; - const day = @mod(@divFloor(g.real_ns, std.time.ns_per_s) + g.gmtoff, 86400); - _ = std.fmt.bufPrint(&clock, "{d:0>2}:{d:0>2}:{d:0>2}", .{ @as(u32, @intCast(@divFloor(day, 3600))), @as(u32, @intCast(@mod(@divFloor(day, 60), 60))), @as(u32, @intCast(@mod(day, 60))) }) catch {}; - return clock; - } + if (R == [8]u8) return pardes.Messages.Message.clockText(@divFloor(g.real_ns, std.time.ns_per_s), g.gmtoff); @compileError("tape: no guess of a clock read as " ++ @typeName(R)); } |
