1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
// SPDX-License-Identifier: MIT OR Apache-2.0
//! Process-lifetime monotonic millisecond clock shared across crates.
//!
//! Unlike a wall-clock timestamp (`SystemTime`), this origin is immune to NTP steps and
//! manual clock adjustments — a backward time jump between a writer and a reader can never
//! produce a spurious elapsed-time reading. Intended for in-process liveness/heartbeat
//! signals (e.g. idle-timeout detection) where writer and reader always run in the same
//! process and only relative deltas matter, never the absolute value.
use LazyLock;
use Instant;
static PROCESS_START: = new;
/// Milliseconds elapsed since an arbitrary process-lifetime origin (the first call to any
/// function in this module).
///
/// Monotonic and immune to wall-clock adjustments. Compare two readings with
/// `saturating_sub` to compute an elapsed duration; the absolute value has no meaning on
/// its own.
///
/// # Examples
///
/// ```rust
/// let t0 = zeph_common::monotonic_millis();
/// std::thread::sleep(std::time::Duration::from_millis(5));
/// let t1 = zeph_common::monotonic_millis();
/// assert!(t1 >= t0);
/// assert!(t1.saturating_sub(t0) >= 5);
/// ```