From b3612b89a339a10d2f70b2ae0d3f09a9def8a743 Mon Sep 17 00:00:00 2001 From: DuckDuckWhale Date: Thu, 19 Nov 2020 00:36:42 -0800 Subject: [PATCH] Fix: displaying 0 time on 3572 seconds Previously it is only rounded to the nearest minute after calculating the number of hours, which led to hour calculation showing 0 hour and minutes rounding to 60 and showing 0 minute as well. Now it is properly rounded to the nearest minute before the formatting logic. --- src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 4b2bc24..58b6b61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,6 +47,8 @@ fn main() { .into_json_deserialize::>() .expect("Failed to parse response as UTF-8 string."); let seconds: u64 = times.iter().map(|tracked| tracked.time).sum(); + // round up if more then half a minute is left + let minutes = (seconds + 30) / 60; let mut map = HashMap::new(); for tracked in times { let (time, _) = map @@ -59,8 +61,8 @@ fn main() { println!( "You spent {} hours and {} minutes on {} issues in the last 24 hours{}", - seconds / 3600, - (seconds + 30) / 60 % 60, + minutes / 60, + minutes % 60, times.len(), if times.is_empty() { '.' } else { ':' } );