From ac5da2c16f80612dd3523a1b55af8c5433a215a4 Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Mon, 22 Aug 2022 20:37:50 +1000 Subject: [PATCH] time tracked in list view --- README.md | 2 -- src/tasks.rs | 22 +++++++++++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1b49e9..b561894 100644 --- a/README.md +++ b/README.md @@ -38,8 +38,6 @@ Run `--help` alongside any command to get details on what it does. - List dependencies as a tree on note view below info - Automatically added recurring notes system - Time tracking - - `track` command to track time on a note - - Include time entries and totals on note view - Command to give statistics on time tracking (by tag, and for the last x days) - Due dates - Taken as input when creating notes diff --git a/src/tasks.rs b/src/tasks.rs index d088327..917d705 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -58,6 +58,22 @@ pub struct TimeEntry { minutes : u16, } +impl TimeEntry { + /// Adds up a collection of time entries. + fn total(entries : &Vec) -> (u16, u16) { + let (hours, minutes) = + entries + .into_iter() + .fold((0, 0), |a, e| (a.0 + e.hours, a.1 + e.minutes)); + + let (hours, minutes) = { + (hours + minutes / 60, minutes % 60) + }; + + (hours, minutes) + } +} + impl TimeEntry { pub fn new(hours : u16, minutes : u16) -> Self { @@ -308,19 +324,23 @@ pub fn list(vault_folder : &path::Path) -> Result<(), error::Error> { .load_preset(comfy_table::presets::UTF8_FULL) .apply_modifier(comfy_table::modifiers::UTF8_ROUND_CORNERS) .set_content_arrangement(comfy_table::ContentArrangement::Dynamic); - table.set_header(vec!["Id", "Name", "Tags", "Priority"]); + table.set_header(vec!["Id", "Name", "Tags", "Priority", "Time"]); let mut tasks = Task::load_all(vault_folder, true)?; tasks.sort_by(|t1, t2| t2.data.priority.cmp(&t1.data.priority)); for task in tasks { if !task.data.discarded && !task.data.complete { + + let (hours, minutes) = TimeEntry::total(&task.data.time_entries); + table.add_row( vec![ task.data.id.to_string(), task.data.name, format_hash_set(&task.data.tags)?, task.data.priority.to_string(), + if (hours, minutes) == (0, 0) { String::new() } else { format!("{}:{:0>2}", hours, minutes) }, ] ); }