Skip to main content

seconds_ago

Function seconds_ago 

Source
pub fn seconds_ago(secs: i64) -> DateTime<Utc>
Expand description

A wall-clock anchor secs seconds before the current instant — the one-line Utc::now() - chrono::Duration::seconds(secs) chain lifted to ONE typed owner past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold, and the composition partner of every timed-decision test (or production caller) that needs a “recently-past” anchor to feed elapsed_since or a humantime-parsed budget comparator.

Pre-lift the SAME chain was hand-authored at 21 workspace-wide consumer sites across 6 files, each restating Utc::now() - chrono::Duration::seconds(<N>) verbatim to seed a DateTime<Utc> N seconds in the past:

  • tatara-process — 15 sites across crd.rs + lib.rs + lifetime_clock.rs seeding TTL-expiry, staleness-gate, and observed-anchor tests.
  • tatara-reconciler::claim — 4 sites in the stable-name claim arbiter’s pure decision tests, each seeding a granted_at or created_at anchor for tie-break arithmetic.
  • tatara-pool-reconciler — 2 sites in pool_decide + desired.rs seeding per-member entered_state_at / created_at for pool-convergence dwell-time decisions.

All 21 sites walked the SAME two-link chain — read the wall clock, then subtract a whole-second chrono::Duration — differing only in the second-count N (age_secs parameter, 500, 720, 42, etc.). Post-lift each callsite reads seconds_ago(N) and the wall-clock read + subtraction sink lives at ONE substrate owner.

Return-form axis: DateTime<Utc> — the copy-form anchor every consumer’s downstream signed_duration_since / [elapsed_since] / Time(anchor) composer takes as its second operand. The i64 secs parameter matches chrono::Duration::seconds’s own signature so a negative value (rare but permitted) yields a future anchor, mirroring the pre-lift semantics.

Sibling to elapsed_since on the same (now, anchor) → Δ axis — elapsed_since reads the delta between two given anchors, seconds_ago produces the anchor N seconds before now that the delta consumer needs.

A future normalization (a monotonic-clock cross-check, an injectable time_source: impl Fn() -> DateTime<Utc> for deterministic tests, a per-fleet skew Δ that clamps the wall-clock read past a known-bad range) lands at THIS ONE substrate primitive and every downstream consumer (production callers, test helpers, future timed-decision gates) inherits the upgrade mechanically — no per-site edit at any of the 21 listed callers or at future consumers.