@@ -276,6 +276,8 @@ impl Neg<Duration> for Duration {
276
276
}
277
277
}
278
278
279
+ // NOTE(stage0): Remove impl after a snapshot
280
+ #[ cfg( stage0) ]
279
281
impl Add < Duration , Duration > for Duration {
280
282
fn add ( & self , rhs : & Duration ) -> Duration {
281
283
let mut secs = self . secs + rhs. secs ;
@@ -288,6 +290,21 @@ impl Add<Duration,Duration> for Duration {
288
290
}
289
291
}
290
292
293
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
294
+ impl Add < Duration , Duration > for Duration {
295
+ fn add ( self , rhs : Duration ) -> Duration {
296
+ let mut secs = self . secs + rhs. secs ;
297
+ let mut nanos = self . nanos + rhs. nanos ;
298
+ if nanos >= NANOS_PER_SEC {
299
+ nanos -= NANOS_PER_SEC ;
300
+ secs += 1 ;
301
+ }
302
+ Duration { secs : secs, nanos : nanos }
303
+ }
304
+ }
305
+
306
+ // NOTE(stage0): Remove impl after a snapshot
307
+ #[ cfg( stage0) ]
291
308
impl Sub < Duration , Duration > for Duration {
292
309
fn sub ( & self , rhs : & Duration ) -> Duration {
293
310
let mut secs = self . secs - rhs. secs ;
@@ -300,6 +317,21 @@ impl Sub<Duration,Duration> for Duration {
300
317
}
301
318
}
302
319
320
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
321
+ impl Sub < Duration , Duration > for Duration {
322
+ fn sub ( self , rhs : Duration ) -> Duration {
323
+ let mut secs = self . secs - rhs. secs ;
324
+ let mut nanos = self . nanos - rhs. nanos ;
325
+ if nanos < 0 {
326
+ nanos += NANOS_PER_SEC ;
327
+ secs -= 1 ;
328
+ }
329
+ Duration { secs : secs, nanos : nanos }
330
+ }
331
+ }
332
+
333
+ // NOTE(stage0): Remove impl after a snapshot
334
+ #[ cfg( stage0) ]
303
335
impl Mul < i32 , Duration > for Duration {
304
336
fn mul ( & self , rhs : & i32 ) -> Duration {
305
337
// Multiply nanoseconds as i64, because it cannot overflow that way.
@@ -310,6 +342,19 @@ impl Mul<i32,Duration> for Duration {
310
342
}
311
343
}
312
344
345
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
346
+ impl Mul < i32 , Duration > for Duration {
347
+ fn mul ( self , rhs : i32 ) -> Duration {
348
+ // Multiply nanoseconds as i64, because it cannot overflow that way.
349
+ let total_nanos = self . nanos as i64 * rhs as i64 ;
350
+ let ( extra_secs, nanos) = div_mod_floor_64 ( total_nanos, NANOS_PER_SEC as i64 ) ;
351
+ let secs = self . secs * rhs as i64 + extra_secs;
352
+ Duration { secs : secs, nanos : nanos as i32 }
353
+ }
354
+ }
355
+
356
+ // NOTE(stage0): Remove impl after a snapshot
357
+ #[ cfg( stage0) ]
313
358
impl Div < i32 , Duration > for Duration {
314
359
fn div ( & self , rhs : & i32 ) -> Duration {
315
360
let mut secs = self . secs / * rhs as i64 ;
@@ -328,6 +373,25 @@ impl Div<i32,Duration> for Duration {
328
373
}
329
374
}
330
375
376
+ #[ cfg( not( stage0) ) ] // NOTE(stage0): Remove cfg after a snapshot
377
+ impl Div < i32 , Duration > for Duration {
378
+ fn div ( self , rhs : i32 ) -> Duration {
379
+ let mut secs = self . secs / rhs as i64 ;
380
+ let carry = self . secs - secs * rhs as i64 ;
381
+ let extra_nanos = carry * NANOS_PER_SEC as i64 / rhs as i64 ;
382
+ let mut nanos = self . nanos / rhs + extra_nanos as i32 ;
383
+ if nanos >= NANOS_PER_SEC {
384
+ nanos -= NANOS_PER_SEC ;
385
+ secs += 1 ;
386
+ }
387
+ if nanos < 0 {
388
+ nanos += NANOS_PER_SEC ;
389
+ secs -= 1 ;
390
+ }
391
+ Duration { secs : secs, nanos : nanos }
392
+ }
393
+ }
394
+
331
395
impl fmt:: Show for Duration {
332
396
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
333
397
// technically speaking, negative duration is not valid ISO 8601,
0 commit comments