std/sys/pal/unsupported/
time.rs1use crate::time::Duration;
2
3#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
4pub struct Instant(Duration);
5
6#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
7pub struct SystemTime(Duration);
8
9pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0));
10
11impl Instant {
12 pub fn now() -> Instant {
13 panic!("time not implemented on this platform")
14 }
15
16 pub fn checked_sub_instant(&self, other: &Instant) -> Option<Duration> {
17 self.0.checked_sub(other.0)
18 }
19
20 pub fn checked_add_duration(&self, other: &Duration) -> Option<Instant> {
21 Some(Instant(self.0.checked_add(*other)?))
22 }
23
24 pub fn checked_sub_duration(&self, other: &Duration) -> Option<Instant> {
25 Some(Instant(self.0.checked_sub(*other)?))
26 }
27}
28
29impl SystemTime {
30 pub fn now() -> SystemTime {
31 panic!("time not implemented on this platform")
32 }
33
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)
36 }
37
38 pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> {
39 Some(SystemTime(self.0.checked_add(*other)?))
40 }
41
42 pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> {
43 Some(SystemTime(self.0.checked_sub(*other)?))
44 }
45}