From abe4d6e47df9380c5397590152fd807aedb81e75 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 29 Jun 2017 20:24:47 -0700 Subject: [PATCH] Do not panic on duration of zero This was causing sporadic issues on Redox. --- src/pb.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pb.rs b/src/pb.rs index 461823f7..004ec6e9 100644 --- a/src/pb.rs +++ b/src/pb.rs @@ -479,11 +479,13 @@ impl Write for ProgressBar { } fn time_to_std(d: time::Duration) -> Duration { - assert!(d > time::Duration::zero()); - - let secs = d.num_seconds(); - let nsecs = (d - time::Duration::seconds(secs)).num_nanoseconds().unwrap(); - Duration::new(secs as u64, nsecs as u32) + if d > time::Duration::zero() { + let secs = d.num_seconds(); + let nsecs = (d - time::Duration::seconds(secs)).num_nanoseconds().unwrap(); + Duration::new(secs as u64, nsecs as u32) + } else { + Duration::new(0, 1) + } } fn fract_dur(d: Duration) -> f64 {