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.
This commit is contained in:
DuckDuckWhale 2020-11-19 00:36:42 -08:00
parent 899232ff92
commit b3612b89a3

View File

@ -47,6 +47,8 @@ fn main() {
.into_json_deserialize::<Vec<TrackedTime>>()
.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 { ':' }
);