Skip to content

Commit 552775b

Browse files
committed
Auto merge of #1287 - RalfJung:time-sub, r=RalfJung
test subtracting SystemTime and Instant
2 parents d1e06b4 + 26b5012 commit 552775b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/run-pass/time.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,22 @@ fn main() {
99
for _ in 0..10 { drop(vec![42]); }
1010
let now2 = SystemTime::now();
1111
assert!(now2 > now1);
12+
let diff = now2.duration_since(now1).unwrap();
13+
assert!(diff.as_micros() > 0);
14+
assert_eq!(now1 + diff, now2);
15+
assert_eq!(now2 - diff, now1);
1216

1317
let now1 = Instant::now();
1418
// Do some work to make time pass.
1519
for _ in 0..10 { drop(vec![42]); }
1620
let now2 = Instant::now();
1721
assert!(now2 > now1);
22+
23+
#[cfg(target_os = "linux")] // TODO: macOS does not support Instant subtraction
24+
{
25+
let diff = now2.duration_since(now1);
26+
assert!(diff.as_micros() > 0);
27+
assert_eq!(now1 + diff, now2);
28+
assert_eq!(now2 - diff, now1);
29+
}
1830
}

0 commit comments

Comments
 (0)