1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
use std::time; pub fn current_timestamp() -> anyhow::Result<String> { Ok(time::SystemTime::now() .duration_since(time::UNIX_EPOCH)? .as_secs() .to_string()) } #[cfg(test)] mod tests { use super::*; #[test] fn test_current_timestamp() -> anyhow::Result<()> { let timestamp = current_timestamp()?; dbg!(×tamp); assert!(timestamp.parse::<i64>().is_ok()); Ok(()) } }