Files
continuwuity/src/core/utils/time.rs
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
561 B
Rust
Raw Normal View History

2024-07-04 12:58:53 +00:00
use std::time::{SystemTime, UNIX_EPOCH};
2024-07-03 00:57:50 +00:00
#[inline]
#[must_use]
#[allow(clippy::as_conversions)]
2024-07-03 19:13:49 +00:00
pub fn now_millis() -> u64 {
UNIX_EPOCH
.elapsed()
.expect("positive duration after epoch")
2024-07-03 00:57:50 +00:00
.as_millis() as u64
}
2024-07-03 01:08:54 +00:00
#[must_use]
pub fn rfc2822_from_seconds(epoch: i64) -> String {
use chrono::{DateTime, Utc};
DateTime::<Utc>::from_timestamp(epoch, 0)
.unwrap_or_default()
.to_rfc2822()
}
2024-07-04 12:58:53 +00:00
#[must_use]
pub fn format(ts: SystemTime, str: &str) -> String {
use chrono::{DateTime, Utc};
let dt: DateTime<Utc> = ts.into();
dt.format(str).to_string()
}