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:
parent
899232ff92
commit
b3612b89a3
@ -47,6 +47,8 @@ fn main() {
|
|||||||
.into_json_deserialize::<Vec<TrackedTime>>()
|
.into_json_deserialize::<Vec<TrackedTime>>()
|
||||||
.expect("Failed to parse response as UTF-8 string.");
|
.expect("Failed to parse response as UTF-8 string.");
|
||||||
let seconds: u64 = times.iter().map(|tracked| tracked.time).sum();
|
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();
|
let mut map = HashMap::new();
|
||||||
for tracked in times {
|
for tracked in times {
|
||||||
let (time, _) = map
|
let (time, _) = map
|
||||||
@ -59,8 +61,8 @@ fn main() {
|
|||||||
|
|
||||||
println!(
|
println!(
|
||||||
"You spent {} hours and {} minutes on {} issues in the last 24 hours{}",
|
"You spent {} hours and {} minutes on {} issues in the last 24 hours{}",
|
||||||
seconds / 3600,
|
minutes / 60,
|
||||||
(seconds + 30) / 60 % 60,
|
minutes % 60,
|
||||||
times.len(),
|
times.len(),
|
||||||
if times.is_empty() { '.' } else { ':' }
|
if times.is_empty() { '.' } else { ':' }
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user