aboutsummaryrefslogtreecommitdiff
path: root/src/util/time.rs
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-03-20 20:38:44 +0100
committerAlex Auvolat <alex@adnab.me>2021-04-27 16:37:10 +0200
commitf9bd2d8fb79a8f3dbea54834b39e65438846ea5c (patch)
tree1d8e8bc66f80e29205893dc35187c0980f46f822 /src/util/time.rs
parentbf36f1f16aae763feae7bc7365741d8406f053cb (diff)
downloadgarage-f9bd2d8fb79a8f3dbea54834b39e65438846ea5c.tar.gz
garage-f9bd2d8fb79a8f3dbea54834b39e65438846ea5c.zip
document util crate
Diffstat (limited to 'src/util/time.rs')
-rw-r--r--src/util/time.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/util/time.rs b/src/util/time.rs
index 148860e0..dfedcb26 100644
--- a/src/util/time.rs
+++ b/src/util/time.rs
@@ -1,6 +1,8 @@
+//! Module containing helper functions to manipulate time
use chrono::{SecondsFormat, TimeZone, Utc};
use std::time::{SystemTime, UNIX_EPOCH};
+/// Returns milliseconds since UNIX Epoch
pub fn now_msec() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
@@ -8,6 +10,8 @@ pub fn now_msec() -> u64 {
.as_millis() as u64
}
+/// Convert a timestamp represented as milliseconds since UNIX Epoch to
+/// its RFC3339 representation, such as "2021-01-01T12:30:00Z"
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;