From 5723151cfb6ef1ac378dc6b221e9a0e34a407581 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sun, 28 Jul 2024 11:37:36 +0300 Subject: [PATCH] feat: properly format tracked time --- README.md | 2 +- src/task.rs | 3 ++- src/tasks.rs | 7 +++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 63f8aa2..3260726 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ An active tag or state filter will also create new tasks with those correspondin - `path` - name including parent tasks - `rpath` - name including parent tasks up to active task - `time` - time tracked -- `ttime` - time tracked including subtasks +- `rtime` - time tracked including subtasks - TBI: `progress` - how many subtasks are complete - TBI: `progressp` - subtask completion in percent diff --git a/src/task.rs b/src/task.rs index bc643a0..2a858cc 100644 --- a/src/task.rs +++ b/src/task.rs @@ -1,5 +1,6 @@ use std::collections::{BTreeSet, HashSet}; use std::fmt; +use std::ops::Div; use nostr_sdk::{Event, EventBuilder, EventId, Kind, Tag, Timestamp}; @@ -124,7 +125,7 @@ impl Task { "parentid" => self.parent_id().map(|i| i.to_string()), "state" => self.state().map(|s| s.to_string()), "name" => Some(self.event.content.clone()), - "time" => Some(self.time_tracked().to_string()), // TODO: format properly + "time" => Some(format!("{}m", self.time_tracked().div(60))), "tags" => self.tags.as_ref().map(|tags| { tags.iter() .map(|t| format!("{}", t.content().unwrap())) diff --git a/src/tasks.rs b/src/tasks.rs index 2401ea1..48c7a47 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -37,7 +37,7 @@ impl Tasks { tasks: Default::default(), properties: vec![ "state".into(), - "ttime".into(), + "rtime".into(), "rpath".into(), "tags".into(), "desc".into(), @@ -192,7 +192,10 @@ impl Tasks { self.traverse_up_from(Some(task.event.id)) .take_while(|t| Some(t.event.id) != self.position) ), - "ttime" => self.total_time_tracked(&task.event.id).to_string(), + "rtime" => { + let time = self.total_time_tracked(&task.event.id); + format!("{:02}:{:02}", time / 3600, time / 60 % 60) + }, prop => task.get(prop).unwrap_or(String::new()), }) .collect::>()