Skip to main content

Module time

Module time 

Source
Expand description

Wall-clock time primitives — the small typed layer over the chrono::DateTime<Utc>std::time::Duration bridge every timed decision in the workspace passes through, plus the K8s wire-form composers (tombstone_now, tombstone_at) that lift a DateTime<Utc> anchor into the Option<Time> shape ObjectMeta::deletion_timestamp (and its metadata-Time peers) carry.

Kubernetes exposes wall-clock anchors on the wire as k8s_openapi::apimachinery::pkg::apis::meta::v1::Time (DateTime<Utc> after .0) — metadata.creationTimestamp, metadata.deletionTimestamp, status.phaseSince, PoolMember.enteredStateAt, etc. Every timed decision (TTL expiry, sleep-budget picker, staleness gate) then projects (now, anchor) onto an Option<std::time::Duration> so it can be compared to a humantime-parsed budget (also std::time::Duration). This module owns the one-line chain that projection reduces to on the READ side, and — via tombstone_now and tombstone_at — the 5-token Some(Time(<anchor>)) wire wrap every WRITE-side fixture that seeds a tombstone-present corner stamps on the metadata slot.

Functions§

at_epoch_second
A DateTime<Utc> anchor at the whole-second Unix epoch offset secs — the one-line DateTime::<Utc>::from_timestamp(secs, 0) .expect("valid epoch second") chain lifted to ONE typed owner past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold, and the deterministic-anchor peer of the wall-clock-reading composers seconds_ago / tombstone_now on the same → DateTime<Utc> axis.
elapsed_since
Elapsed wall-clock time between anchor and now, or None if anchor is in now’s future (a clock rewind or a mis-sequenced anchor). The one-line now.signed_duration_since(anchor).to_std() .ok() chain lifted to ONE typed owner past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold, and the peer of every timed-decision gate that compares an anchor to a humantime-parsed budget.
parse_rfc3339_opt
Parse an Option<&str> as an RFC-3339 wall-clock stamp, discarding the ParseError arm on the parseable-input axis. The one-line <opt>.and_then(|s| chrono::DateTime::parse_from_rfc3339(s).ok()) chain lifted to ONE typed owner past the ★★ PRIME-DIRECTIVE ≥ 2 duplication threshold, and the sibling of every timed-decision assertion / API-input parser that reads an RFC-3339 stamp out of a JSON slot, an HTTP query param, or a K8s status-subresource value.
seconds_ago
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.
tombstone_at
A tombstone stamp for a K8s metadata.deletionTimestamp slot at the operator-supplied when anchor — the peer of tombstone_now on the anchor-explicit axis. Composes directly with seconds_ago so a callsite needing a “stamped N seconds ago” tombstone (e.g. a stale-tombstone garbage-collection probe, a fixture that seeds a tombstone predating the reconciler’s now by enough to trip a deletion_grace_period_seconds cutoff) reads tombstone_at(seconds_ago(N)) and routes through ONE substrate owner for both the anchor construction and the wire-form wrap.
tombstone_now
A tombstone stamp for a K8s metadata.deletionTimestamp slot at the current wall-clock instant — the wire shape K8s stamps once the API server has received a DELETE request but the finalizer chain has not yet released the object for GC. The Option<Time> return form matches the slot’s own type (ObjectMeta::deletion_timestamp: Option<Time>) so the tombstone composes directly into the metadata without a per-caller Some(...) wrap or a per-caller Time(...) wrap of the Utc::now() read.