diff --git a/Cargo.toml b/Cargo.toml index a52b4138..44f43849 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -208,7 +208,7 @@ features = ["serde"] # standard date and time tools [workspace.dependencies.chrono] version = "0.4.38" -features = ["alloc"] +features = ["alloc", "std"] default-features = false [workspace.dependencies.hyper] diff --git a/src/core/utils/time.rs b/src/core/utils/time.rs index f6208b31..7de00e9e 100644 --- a/src/core/utils/time.rs +++ b/src/core/utils/time.rs @@ -1,9 +1,9 @@ +use std::time::{SystemTime, UNIX_EPOCH}; + #[inline] #[must_use] #[allow(clippy::as_conversions)] pub fn now_millis() -> u64 { - use std::time::UNIX_EPOCH; - UNIX_EPOCH .elapsed() .expect("positive duration after epoch") @@ -18,3 +18,11 @@ pub fn rfc2822_from_seconds(epoch: i64) -> String { .unwrap_or_default() .to_rfc2822() } + +#[must_use] +pub fn format(ts: SystemTime, str: &str) -> String { + use chrono::{DateTime, Utc}; + + let dt: DateTime = ts.into(); + dt.format(str).to_string() +}