use crate::time::Duration; const SECS_IN_MINUTE: u64 = 60; const SECS_IN_HOUR: u64 = SECS_IN_MINUTE * 60; const SECS_IN_DAY: u64 = SECS_IN_HOUR * 24; #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct Instant(Duration); #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct SystemTime(Duration); pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0)); impl Instant { pub fn now() -> Instant { // If we have a timestamp protocol, use it. if let Some(x) = instant_internal::timestamp_protocol() { return x; } if let Some(x) = instant_internal::platform_specific() { return x; } panic!("time not implemented on this platform") } pub fn checked_sub_instant(&self, other: &Instant) -> Option { self.0.checked_sub(other.0) } pub fn checked_add_duration(&self, other: &Duration) -> Option { Some(Instant(self.0.checked_add(*other)?)) } pub fn checked_sub_duration(&self, other: &Duration) -> Option { Some(Instant(self.0.checked_sub(*other)?)) } } impl SystemTime { pub fn now() -> SystemTime { system_time_internal::now() .unwrap_or_else(|| panic!("time not implemented on this platform")) } pub fn sub_time(&self, other: &SystemTime) -> Result { self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) } pub fn checked_add_duration(&self, other: &Duration) -> Option { Some(SystemTime(self.0.checked_add(*other)?)) } pub fn checked_sub_duration(&self, other: &Duration) -> Option { Some(SystemTime(self.0.checked_sub(*other)?)) } } pub(crate) mod system_time_internal { use r_efi::efi::{RuntimeServices, Time}; use super::super::helpers; use super::*; use crate::mem::MaybeUninit; use crate::ptr::NonNull; pub fn now() -> Option { let runtime_services: NonNull = helpers::runtime_services()?; let mut t: MaybeUninit