euphony_units/time/
timestamp.rs1use crate::time::duration::Duration;
2use core::ops::{Add, AddAssign, Sub};
3
4#[derive(Clone, Copy, Debug, Default, PartialEq, PartialOrd, Eq, Ord, Hash)]
5pub struct Timestamp(Duration);
6
7impl Timestamp {
8 #[allow(dead_code)]
9 pub(crate) const fn from_duration(duration: Duration) -> Self {
10 Self(duration)
11 }
12
13 pub const fn as_micros(&self) -> u64 {
14 self.0.as_micros() as u64
15 }
16}
17
18impl Add<Duration> for Timestamp {
19 type Output = Timestamp;
20
21 fn add(self, duration: Duration) -> Self::Output {
22 Self(self.0 + duration)
23 }
24}
25
26impl AddAssign<Duration> for Timestamp {
27 fn add_assign(&mut self, duration: Duration) {
28 self.0 += duration;
29 }
30}
31
32impl Sub<Timestamp> for Timestamp {
33 type Output = Duration;
34
35 fn sub(self, duration: Timestamp) -> Self::Output {
36 self.0 - duration.0
37 }
38}