use chrono::Datelike; use std::time::{SystemTime, UNIX_EPOCH}; /// Get the current time since epoch /// /// ``` /// use virtweb_backend::utils::time_utils::time; /// /// let time = time(); /// ``` pub fn time() -> u64 { SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() .as_secs() } /// Format given UNIX time in a simple format pub fn format_date(time: i64) -> anyhow::Result { let date = chrono::DateTime::from_timestamp(time, 0).ok_or(anyhow::anyhow!("invalid date"))?; Ok(format!( "{:0>2}/{:0>2}/{}", date.day(), date.month(), date.year() )) }