tap_msg/utils.rs
1//! Utility functions for TAP core
2//!
3//! This module provides utility functions used throughout the TAP core library.
4
5use crate::error::Error;
6use crate::Result;
7use std::time::SystemTime;
8
9/// Gets the current time as a unix timestamp (seconds since the epoch)
10///
11/// # Returns
12///
13/// * `Result<u64>` - The current time as a unix timestamp, or an error if
14/// the system time cannot be determined.
15pub fn get_current_time() -> Result<u64> {
16 SystemTime::now()
17 .duration_since(SystemTime::UNIX_EPOCH)
18 .map_err(|e| Error::ParseError(format!("Failed to get current time: {}", e)))
19 .map(|duration| duration.as_secs())
20}