Skip to main content

Module log_time

Module log_time 

Source
Expand description

§Module: log_time

Human-readable log timestamps (#opslogts). Operators read the supervisor session log and .agent-doc/logs/ops.log to verify reported issues, and a bare Unix epoch like 1781771180 is not legible. This module formats every log entry’s timestamp as ISO-8601 UTC and parses it back, with no external date dependency (Howard Hinnant’s civil-date algorithms).

§Spec

  • format_log_timestamp renders a Unix epoch (seconds) as YYYY-MM-DDTHH:MM:SSZ (UTC).
  • parse_log_timestamp is the matching reader: it accepts either a bare Unix epoch (pre-#opslogts log lines and cycles.jsonl timestamps) or an ISO-8601 UTC string and returns epoch seconds. This backward compatibility keeps the staleness / accretion / startup-miss / gate_verify scanners working across the format switch — old [<epoch>] lines still parse, and parse(format(x)) == x round-trips.

§Agentic Contracts

  • Pure and deterministic for unit testing; no I/O, no clock reads.
  • parse_log_timestamp fails closed (None) on garbage rather than mapping it to 0, so a malformed line is skipped, not mis-windowed.

Functions§

format_log_timestamp
Format a Unix epoch (seconds) as a human-readable ISO-8601 UTC timestamp YYYY-MM-DDTHH:MM:SSZ (#opslogts).
parse_log_timestamp
Parse a log timestamp that is either a bare Unix epoch (seconds) or an ISO-8601 UTC string YYYY-MM-DDTHH:MM:SSZ, returning epoch seconds (#opslogts). The trailing Z is optional. Returns None on anything that is neither, so the staleness/gate scanners skip a malformed line.