1 use crate::time::Duration;
3 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
4 pub struct Instant(Duration);
6 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
7 pub struct SystemTime(Duration);
9 pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
12 pub fn now() -> Instant {
13 panic!("time not implemented on this platform")
16 pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
17 self.0.checked_sub(other.0)
20 pub fn checked_add_duration(&self, other: &Duration) -> Option<Instant> {
21 Some(Instant(self.0.checked_add(*other)?))
24 pub fn checked_sub_duration(&self, other: &Duration) -> Option<Instant> {
25 Some(Instant(self.0.checked_sub(*other)?))
30 pub fn now() -> SystemTime {
31 panic!("time not implemented on this platform")
34 pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> {
35 self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0)
38 pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> {
39 Some(SystemTime(self.0.checked_add(*other)?))
42 pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> {
43 Some(SystemTime(self.0.checked_sub(*other)?))