1 use super::abi::usercalls;
2 use crate::time::Duration;
4 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
5 pub struct Instant(Duration);
7 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
8 pub struct SystemTime(Duration);
10 pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
13 pub fn now() -> Instant {
14 Instant(usercalls::insecure_time())
17 pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
18 self.0.checked_sub(other.0)
21 pub fn checked_add_duration(&self, other: &Duration) -> Option<Instant> {
22 Some(Instant(self.0.checked_add(*other)?))
25 pub fn checked_sub_duration(&self, other: &Duration) -> Option<Instant> {
26 Some(Instant(self.0.checked_sub(*other)?))
31 pub fn now() -> SystemTime {
32 SystemTime(usercalls::insecure_time())
35 pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {
36 self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0)
39 pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> {
40 Some(SystemTime(self.0.checked_add(*other)?))
43 pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> {
44 Some(SystemTime(self.0.checked_sub(*other)?))