auto merge of #18926 : alexcrichton/rust/issue-18925, r=huonw
The subtraction was erroneously backwards, returning negative durations! Closes #18925
This commit is contained in:
commit
b1c84d6be8
2 changed files with 9 additions and 2 deletions
|
@ -35,7 +35,7 @@ pub fn time<T, U>(do_it: bool, what: &str, u: U, f: |U| -> T) -> T {
|
||||||
let rv = rv.unwrap();
|
let rv = rv.unwrap();
|
||||||
|
|
||||||
println!("{}time: {}.{:03} \t{}", " ".repeat(old),
|
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));
|
depth.replace(Some(old));
|
||||||
|
|
||||||
rv
|
rv
|
||||||
|
|
|
@ -140,7 +140,7 @@ impl Duration {
|
||||||
pub fn span(f: ||) -> Duration {
|
pub fn span(f: ||) -> Duration {
|
||||||
let before = super::precise_time_ns();
|
let before = super::precise_time_ns();
|
||||||
f();
|
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.
|
/// 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)),
|
assert_eq!(format!("{:30}", Duration::days(1) + Duration::milliseconds(2345)),
|
||||||
"P1DT2.345S".to_string());
|
"P1DT2.345S".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn span() {
|
||||||
|
use io::timer::sleep;
|
||||||
|
let dur = Duration::span(|| sleep(Duration::milliseconds(5)));
|
||||||
|
assert!(dur > Duration::milliseconds(1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue