Skip to content

Commit

Permalink
Merge pull request #54 from ids1024/duration
Browse files Browse the repository at this point in the history
Do not panic on duration of zero
  • Loading branch information
a8m committed Jul 29, 2017
2 parents fe5f8ba + abe4d6e commit e9369ed
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,11 +479,13 @@ impl<T: Write> Write for ProgressBar<T> {
}

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 {
Expand Down

0 comments on commit e9369ed

Please sign in to comment.