From d32d60c868810b4dafdd12effee60ca11342b7a7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 19 Apr 2022 19:37:58 +0200 Subject: [PATCH] common: Add SecondsSinceUnixEpoch::now --- crates/ruma-common/src/time.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/ruma-common/src/time.rs b/crates/ruma-common/src/time.rs index 5a699ef1..232da64d 100644 --- a/crates/ruma-common/src/time.rs +++ b/crates/ruma-common/src/time.rs @@ -57,6 +57,11 @@ impl SecondsSinceUnixEpoch { Some(Self(millis)) } + /// The current system-time as seconds since the unix epoch. + pub fn now() -> Self { + Self::from_system_time(SystemTime::now()).unwrap() + } + /// Creates a new `SystemTime` from `self`, if it can be represented. pub fn to_system_time(self) -> Option { UNIX_EPOCH.checked_add(Duration::from_secs(self.0.into()))