@@ -99,6 +99,8 @@ impl Timespec {
99
99
}
100
100
}
101
101
102
+ // NOTE(stage0): Remove impl after a snapshot
103
+ #[ cfg( stage0) ]
102
104
impl Add < Duration , Timespec > for Timespec {
103
105
fn add ( & self , other : & Duration ) -> Timespec {
104
106
let d_sec = other. num_seconds ( ) ;
@@ -119,6 +121,29 @@ impl Add<Duration, Timespec> for Timespec {
119
121
}
120
122
}
121
123
124
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
125
+ impl Add < Duration , Timespec > for Timespec {
126
+ fn add ( self , other : Duration ) -> Timespec {
127
+ let d_sec = other. num_seconds ( ) ;
128
+ // It is safe to unwrap the nanoseconds, because there cannot be
129
+ // more than one second left, which fits in i64 and in i32.
130
+ let d_nsec = ( other - Duration :: seconds ( d_sec) )
131
+ . num_nanoseconds ( ) . unwrap ( ) as i32 ;
132
+ let mut sec = self . sec + d_sec;
133
+ let mut nsec = self . nsec + d_nsec;
134
+ if nsec >= NSEC_PER_SEC {
135
+ nsec -= NSEC_PER_SEC ;
136
+ sec += 1 ;
137
+ } else if nsec < 0 {
138
+ nsec += NSEC_PER_SEC ;
139
+ sec -= 1 ;
140
+ }
141
+ Timespec :: new ( sec, nsec)
142
+ }
143
+ }
144
+
145
+ // NOTE(stage0): Remove impl after a snapshot
146
+ #[ cfg( stage0) ]
122
147
impl Sub < Timespec , Duration > for Timespec {
123
148
fn sub ( & self , other : & Timespec ) -> Duration {
124
149
let sec = self . sec - other. sec ;
@@ -127,6 +152,15 @@ impl Sub<Timespec, Duration> for Timespec {
127
152
}
128
153
}
129
154
155
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
156
+ impl Sub < Timespec , Duration > for Timespec {
157
+ fn sub ( self , other : Timespec ) -> Duration {
158
+ let sec = self . sec - other. sec ;
159
+ let nsec = self . nsec - other. nsec ;
160
+ Duration :: seconds ( sec) + Duration :: nanoseconds ( nsec as i64 )
161
+ }
162
+ }
163
+
130
164
/// Returns the current time as a `timespec` containing the seconds and
131
165
/// nanoseconds since 1970-01-01T00:00:00Z.
132
166
pub fn get_time ( ) -> Timespec {
0 commit comments