Skip to main content

canic_backup/timestamp/
mod.rs

1//! Module: timestamp
2//!
3//! Responsibility: generate compact wall-clock markers for backup metadata.
4//! Does not own: clock synchronization, ordering guarantees, or persistence.
5//! Boundary: supplies human-readable timestamps to backup journals and reports.
6
7use std::time::{SystemTime, UNIX_EPOCH};
8
9/// Return the current wall-clock timestamp as a compact unix-seconds marker.
10#[must_use]
11pub fn current_timestamp_marker() -> String {
12    let seconds = SystemTime::now()
13        .duration_since(UNIX_EPOCH)
14        .map_or(0, |duration| duration.as_secs());
15
16    format!("unix:{seconds}")
17}
18
19#[cfg(test)]
20mod tests {
21    use super::*;
22
23    // Ensure generated timestamp markers use the stable unix-seconds prefix.
24    #[test]
25    fn current_timestamp_marker_uses_unix_prefix() {
26        let marker = current_timestamp_marker();
27        let seconds = marker
28            .strip_prefix("unix:")
29            .expect("timestamp marker should include prefix");
30
31        assert!(seconds.parse::<u64>().is_ok());
32    }
33}