1use crate::TSpan;
2use core::cmp::Ordering;
3use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
4
5impl Add<TSpan> for TSpan {
6 type Output = Self;
7
8 #[inline]
10 fn add(self, rhs: TSpan) -> Self {
11 self.add(rhs)
12 }
13}
14
15impl AddAssign<TSpan> for TSpan {
16 #[inline]
18 fn add_assign(&mut self, rhs: TSpan) {
19 *self = self.add(rhs);
20 }
21}
22
23impl Sub<TSpan> for TSpan {
24 type Output = Self;
25
26 #[inline]
28 fn sub(self, rhs: TSpan) -> Self {
29 self.sub(rhs)
30 }
31}
32
33impl SubAssign<TSpan> for TSpan {
34 #[inline]
36 fn sub_assign(&mut self, rhs: TSpan) {
37 *self = self.sub(rhs);
38 }
39}
40
41impl Neg for TSpan {
42 type Output = Self;
43
44 #[inline]
46 fn neg(self) -> Self {
47 self.neg()
48 }
49}
50
51impl Mul<i64> for TSpan {
52 type Output = Self;
53
54 #[inline]
56 fn mul(self, rhs: i64) -> Self {
57 self.mul(rhs)
58 }
59}
60
61impl MulAssign<i64> for TSpan {
62 #[inline]
64 fn mul_assign(&mut self, rhs: i64) {
65 *self = self.mul(rhs);
66 }
67}
68
69impl Div<i64> for TSpan {
70 type Output = Self;
71
72 #[inline]
74 fn div(self, rhs: i64) -> Self {
75 self.div(rhs)
76 }
77}
78
79impl DivAssign<i64> for TSpan {
80 #[inline]
82 fn div_assign(&mut self, rhs: i64) {
83 *self = self.div(rhs);
84 }
85}
86
87impl TSpan {
88 pub const fn cmp(self, other: Self) -> Ordering {
92 if self.sec < other.sec {
93 Ordering::Less
94 } else if self.sec > other.sec {
95 Ordering::Greater
96 } else if self.attos < other.attos {
97 Ordering::Less
98 } else if self.attos > other.attos {
99 Ordering::Greater
100 } else {
101 Ordering::Equal
102 }
103 }
104
105 pub const fn min(self, other: Self) -> Self {
109 match self.cmp(other) {
110 Ordering::Greater => other,
111 _ => self,
112 }
113 }
114
115 pub const fn max(self, other: Self) -> Self {
119 match self.cmp(other) {
120 Ordering::Less => other,
121 _ => self,
122 }
123 }
124
125 pub const fn lt(self, other: Self) -> bool {
129 matches!(self.cmp(other), Ordering::Less)
130 }
131
132 pub const fn gt(self, other: Self) -> bool {
136 matches!(self.cmp(other), Ordering::Greater)
137 }
138
139 pub const fn le(self, other: Self) -> bool {
143 !matches!(self.cmp(other), Ordering::Greater)
144 }
145
146 pub const fn ge(self, other: Self) -> bool {
150 !matches!(self.cmp(other), Ordering::Less)
151 }
152}