Skip to main content

canic_backup/timestamp/
mod.rs

1use std::time::{SystemTime, UNIX_EPOCH};
2
3/// Return the current wall-clock timestamp as a compact unix-seconds marker.
4#[must_use]
5pub fn current_timestamp_marker() -> String {
6    let seconds = SystemTime::now()
7        .duration_since(UNIX_EPOCH)
8        .map_or(0, |duration| duration.as_secs());
9
10    format!("unix:{seconds}")
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16
17    // Ensure generated timestamp markers use the stable unix-seconds prefix.
18    #[test]
19    fn current_timestamp_marker_uses_unix_prefix() {
20        let marker = current_timestamp_marker();
21        let seconds = marker
22            .strip_prefix("unix:")
23            .expect("timestamp marker should include prefix");
24
25        assert!(seconds.parse::<u64>().is_ok());
26    }
27}