diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-11-13 08:48:38 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-11-13 09:03:33 -0800 |
| commit | 877139495d4c572493f2440cff038283a3ba4e5e (patch) | |
| tree | e51d2daf98a158535741ffe74b12ba6afe24cbf3 /src/libstd/time | |
| parent | 37ea270accf97fc4eed21a7373c3e7e62de7bbeb (diff) | |
| download | rust-877139495d4c572493f2440cff038283a3ba4e5e.tar.gz rust-877139495d4c572493f2440cff038283a3ba4e5e.zip | |
std: Fix the return value of Duration::span
The subtraction was erroneously backwards, returning negative durations! Closes #18925
Diffstat (limited to 'src/libstd/time')
| -rw-r--r-- | src/libstd/time/duration.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libstd/time/duration.rs b/src/libstd/time/duration.rs index c2d4afeb9ad..8892884045a 100644 --- a/src/libstd/time/duration.rs +++ b/src/libstd/time/duration.rs @@ -140,7 +140,7 @@ impl Duration { pub fn span(f: ||) -> Duration { let before = super::precise_time_ns(); f(); - Duration::nanoseconds((before - super::precise_time_ns()) as i64) + Duration::nanoseconds((super::precise_time_ns() - before) as i64) } /// Returns the total number of whole weeks in the duration. @@ -565,4 +565,11 @@ mod tests { assert_eq!(format!("{:30}", Duration::days(1) + Duration::milliseconds(2345)), "P1DT2.345S".to_string()); } + + #[test] + fn span() { + use io::timer::sleep; + let dur = Duration::span(|| sleep(Duration::milliseconds(5))); + assert!(dur > Duration::milliseconds(1)); + } } |
