From 3fc3388e364c3378ad914cdf334186229a4425af Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Thu, 25 Aug 2022 09:26:33 +1000 Subject: [PATCH] tracked time total --- src/stats.rs | 10 ++++++++++ src/tasks.rs | 11 +++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/stats.rs b/src/stats.rs index 2c9702f..1d584b8 100644 --- a/src/stats.rs +++ b/src/stats.rs @@ -72,6 +72,7 @@ pub fn time_per_tag(days : u16, vault_folder : &path::Path) -> Result<(), error: table.set_header(vec!["Tag", "Time"]); + let mut total_duration = tasks::Duration::zero(); for (tag, duration) in times { table.add_row( vec![ @@ -79,8 +80,17 @@ pub fn time_per_tag(days : u16, vault_folder : &path::Path) -> Result<(), error: duration.to_string(), ] ); + + total_duration = total_duration + duration; } + table.add_row( + vec![ + String::from("Total"), + total_duration.to_string(), + ] + ); + println!("{}", table); Ok(()) diff --git a/src/tasks.rs b/src/tasks.rs index 373ff91..754d08d 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -273,9 +273,16 @@ impl Task { // Sort entries by date. entries.sort_by(|e1, e2| e1.logged_date.cmp(&e2.logged_date)); - println!("Time Entries:"); + let mut total = Duration::zero(); + let mut lines = Vec::with_capacity(entries.len()); for entry in &entries { - println!(" {} [{}]", entry.duration, entry.logged_date); + lines.push(format!(" {} [{}]", entry.duration, entry.logged_date)); + total = total + entry.duration; + } + + println!("Time Entries (totaling {}):", total); + for line in lines { + println!("{}", line); } }