about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-11-13 23:37:21 +0000
committerbors <bors@rust-lang.org>2014-11-13 23:37:21 +0000
commitb1c84d6be803dd2ea8a68b82fea60c45dde773f1 (patch)
tree2e1686ee137434a608595856b7850a4357a5b85f /src
parent15ba87f0314fda5e81603f37ae5f40e2022bcfc1 (diff)
parent877139495d4c572493f2440cff038283a3ba4e5e (diff)
downloadrust-b1c84d6be803dd2ea8a68b82fea60c45dde773f1.tar.gz
rust-b1c84d6be803dd2ea8a68b82fea60c45dde773f1.zip
auto merge of #18926 : alexcrichton/rust/issue-18925, r=huonw
The subtraction was erroneously backwards, returning negative durations!

Closes #18925
Diffstat (limited to 'src')
-rw-r--r--src/librustc/util/common.rs2
-rw-r--r--src/libstd/time/duration.rs9
2 files changed, 9 insertions, 2 deletions
diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs
index b845e507fd3..06154f68613 100644
--- a/src/librustc/util/common.rs
+++ b/src/librustc/util/common.rs
@@ -35,7 +35,7 @@ pub fn time<T, U>(do_it: bool, what: &str, u: U, f: |U| -> T) -> T {
     let rv = rv.unwrap();
 
     println!("{}time: {}.{:03} \t{}", "  ".repeat(old),
-             dur.num_seconds(), dur.num_milliseconds(), what);
+             dur.num_seconds(), dur.num_milliseconds() % 1000, what);
     depth.replace(Some(old));
 
     rv
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));
+    }
 }