diff options
author | Alex Auvolat <alex@adnab.me> | 2021-03-15 16:21:41 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2021-03-15 16:21:41 +0100 |
commit | 3bf2df622a070fe8f233bec6d60bd5cca995fbfc (patch) | |
tree | 65ba71d4b950208c177a96ba34b797f18e732d5b /src/util/time.rs | |
parent | 097c339d981dba0420af17d30d1221181d8bf1d7 (diff) | |
download | garage-3bf2df622a070fe8f233bec6d60bd5cca995fbfc.tar.gz garage-3bf2df622a070fe8f233bec6d60bd5cca995fbfc.zip |
Time and metadata improvements
Diffstat (limited to 'src/util/time.rs')
-rw-r--r-- | src/util/time.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util/time.rs b/src/util/time.rs new file mode 100644 index 00000000..148860e0 --- /dev/null +++ b/src/util/time.rs @@ -0,0 +1,16 @@ +use chrono::{SecondsFormat, TimeZone, Utc}; +use std::time::{SystemTime, UNIX_EPOCH}; + +pub fn now_msec() -> u64 { + SystemTime::now() + .duration_since(UNIX_EPOCH) + .expect("Fix your clock :o") + .as_millis() as u64 +} + +pub fn msec_to_rfc3339(msecs: u64) -> String { + let secs = msecs as i64 / 1000; + let nanos = (msecs as i64 % 1000) as u32 * 1_000_000; + let timestamp = Utc.timestamp(secs, nanos); + timestamp.to_rfc3339_opts(SecondsFormat::Secs, true) +} |