ruma-common: Add getters to [Milli]SecondsSinceUnixEpoch
This commit is contained in:
parent
a238a0dda5
commit
8a147f08d1
@ -1,4 +1,4 @@
|
|||||||
use js_int::UInt;
|
use js_int::{uint, UInt};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
@ -28,6 +28,16 @@ impl MilliSecondsSinceUnixEpoch {
|
|||||||
pub fn to_system_time(self) -> Option<SystemTime> {
|
pub fn to_system_time(self) -> Option<SystemTime> {
|
||||||
UNIX_EPOCH.checked_add(Duration::from_millis(self.0.into()))
|
UNIX_EPOCH.checked_add(Duration::from_millis(self.0.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the time since the unix epoch in milliseconds.
|
||||||
|
pub fn get(&self) -> UInt {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get time since the unix epoch in seconds.
|
||||||
|
pub fn as_secs(&self) -> UInt {
|
||||||
|
self.0 / uint!(1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A timestamp represented as the number of seconds since the unix epoch.
|
/// A timestamp represented as the number of seconds since the unix epoch.
|
||||||
@ -48,6 +58,11 @@ impl SecondsSinceUnixEpoch {
|
|||||||
pub fn to_system_time(self) -> Option<SystemTime> {
|
pub fn to_system_time(self) -> Option<SystemTime> {
|
||||||
UNIX_EPOCH.checked_add(Duration::from_secs(self.0.into()))
|
UNIX_EPOCH.checked_add(Duration::from_secs(self.0.into()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get time since the unix epoch in seconds.
|
||||||
|
pub fn get(&self) -> UInt {
|
||||||
|
self.0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user