diff --git a/crates/ruma-common/src/time.rs b/crates/ruma-common/src/time.rs index f963dc37..4261147d 100644 --- a/crates/ruma-common/src/time.rs +++ b/crates/ruma-common/src/time.rs @@ -24,7 +24,7 @@ impl MilliSecondsSinceUnixEpoch { /// The current system time in milliseconds since the unix epoch. pub fn now() -> Self { #[cfg(not(all(target_arch = "wasm32", target_os = "unknown", feature = "js")))] - return Self::from_system_time(SystemTime::now()).unwrap(); + return Self::from_system_time(SystemTime::now()).expect("date out of range"); #[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "js"))] return Self(f64_to_uint(js_sys::Date::now())); @@ -64,7 +64,7 @@ impl SecondsSinceUnixEpoch { /// The current system-time as seconds since the unix epoch. pub fn now() -> Self { #[cfg(not(all(target_arch = "wasm32", target_os = "unknown", feature = "js")))] - return Self::from_system_time(SystemTime::now()).unwrap(); + return Self::from_system_time(SystemTime::now()).expect("date out of range"); #[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "js"))] return Self(f64_to_uint(js_sys::Date::now() / 1000.0)); @@ -84,7 +84,9 @@ impl SecondsSinceUnixEpoch { #[cfg(all(target_arch = "wasm32", target_os = "unknown", feature = "js"))] fn f64_to_uint(val: f64) -> UInt { use std::convert::TryFrom; - UInt::try_from(val as u64).unwrap() + // UInt::MAX milliseconds is ~285 616 years, we do not account for that + // (or for dates before the unix epoch which would have to be negative) + UInt::try_from(val as u64).expect("date out of range") } #[cfg(test)]