diff options
| author | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
|---|---|---|
| committer | aur-build <aur-build@localhost> | 2026-11-19 17:09:59 +0000 |
| commit | e757979f1a2afdbe7146066345bb9acd19d3b151 (patch) | |
| tree | 30d5f5fbccd25ea7bf01c5202684af463b74e7d3 /src/time.rs | |
| parent | 94c318f13264bb3c00a9f3057ba2e1aafb57c9e4 (diff) | |
| download | aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.tar.gz aur-build-e757979f1a2afdbe7146066345bb9acd19d3b151.zip | |
comments: say why, not what
Every module-level `//!` header is gone, and the comments that remained
either re-explained the line below them or had grown into paragraphs.
Density went from one comment line per 6.7 lines of code to one per 10.
827 insertions against 2194 deletions across 86 files.
What survived: the invariants (I1-I12), the design cross-references into
DESIGN.md, and the notes recording a bug that was found and fixed — those
are the comments that carry weight, because they answer a question the
code cannot answer about itself. What did not: restating a function
signature in prose, and narration of the statement underneath.
Diffstat (limited to 'src/time.rs')
| -rw-r--r-- | src/time.rs | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/src/time.rs b/src/time.rs index 88a27c7..b5f077e 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,29 +1,17 @@ -//! Clock helpers. -//! -//! DESIGN.md §16: "use DB time (`strftime` at write) for all ordering and audit -//! stamps". We store timestamps as UTC ISO-8601 with second resolution so that -//! lexicographic ordering equals chronological ordering, and every write path -//! funnels through [`now`] so a test can pin the clock. - use chrono::{DateTime, SecondsFormat, TimeZone, Utc}; /// Current time as a canonical DB timestamp: `2026-11-17T20:43:24Z`. pub fn now() -> String { - // A test may pin the clock (see `pin`); production reads the real clock. match pinned() { Some(pinned) => pinned, None => fmt(Utc::now()), } } -/// The instant relative arithmetic should use. -/// -/// This is what makes `secs_ago` and `secs_ahead` honest under a pinned clock -/// (§6 m-1): a test that pins the clock and then asks for a 90-second lease -/// means a lease expiring 90 seconds after *the pinned instant*, not after the -/// real one. Reading the wall clock here instead would hand a pinned test a -/// lease that had already expired — or would not expire for a century — and the -/// test would pass while proving nothing about expiry at all. +/// The instant relative arithmetic should use, which is what makes `secs_ago` +/// and `secs_ahead` honest under a pinned clock (§6 m-1): a pinned test asking +/// for a 90-second lease means 90 seconds after *the pinned instant*, not after +/// the real one. fn base() -> DateTime<Utc> { match pinned().and_then(|p| parse(&p)) { Some(t) => t, @@ -51,12 +39,10 @@ pub fn pin(ts: &str) -> Option<String> { }) } -/// Unpin the clock for the current thread. pub fn unpin() { CLOCK.with(|c| *c.borrow_mut() = None); } -/// Parse a DB timestamp back into a `DateTime<Utc>`. pub fn parse(ts: &str) -> Option<DateTime<Utc>> { DateTime::parse_from_rfc3339(ts) .ok() @@ -68,19 +54,15 @@ pub fn parse(ts: &str) -> Option<DateTime<Utc>> { }) } -/// Whole seconds between two timestamps (`b - a`), or `None` if unparseable. pub fn delta_secs(a: &str, b: &str) -> Option<i64> { Some(parse(b)?.signed_duration_since(parse(a)?).num_seconds()) } -/// A timestamp `secs` seconds in the past, canonical format. Honors the pinned -/// clock — see [`base`]. +/// A timestamp `secs` from [`base`], canonical format. pub fn secs_ago(secs: i64) -> String { fmt(base() - chrono::Duration::seconds(secs)) } -/// A timestamp `secs` seconds in the future, canonical format. Honors the -/// pinned clock — see [`base`]. pub fn secs_ahead(secs: i64) -> String { fmt(base() + chrono::Duration::seconds(secs)) } |
