feat: properly format tracked time

This commit is contained in:
xeruf 2024-07-28 11:37:36 +03:00
parent 1b361355b0
commit 5723151cfb
3 changed files with 8 additions and 4 deletions

View File

@ -54,7 +54,7 @@ An active tag or state filter will also create new tasks with those correspondin
- `path` - name including parent tasks - `path` - name including parent tasks
- `rpath` - name including parent tasks up to active task - `rpath` - name including parent tasks up to active task
- `time` - time tracked - `time` - time tracked
- `ttime` - time tracked including subtasks - `rtime` - time tracked including subtasks
- TBI: `progress` - how many subtasks are complete - TBI: `progress` - how many subtasks are complete
- TBI: `progressp` - subtask completion in percent - TBI: `progressp` - subtask completion in percent

View File

@ -1,5 +1,6 @@
use std::collections::{BTreeSet, HashSet}; use std::collections::{BTreeSet, HashSet};
use std::fmt; use std::fmt;
use std::ops::Div;
use nostr_sdk::{Event, EventBuilder, EventId, Kind, Tag, Timestamp}; use nostr_sdk::{Event, EventBuilder, EventId, Kind, Tag, Timestamp};
@ -124,7 +125,7 @@ impl Task {
"parentid" => self.parent_id().map(|i| i.to_string()), "parentid" => self.parent_id().map(|i| i.to_string()),
"state" => self.state().map(|s| s.to_string()), "state" => self.state().map(|s| s.to_string()),
"name" => Some(self.event.content.clone()), "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" => self.tags.as_ref().map(|tags| {
tags.iter() tags.iter()
.map(|t| format!("{}", t.content().unwrap())) .map(|t| format!("{}", t.content().unwrap()))

View File

@ -37,7 +37,7 @@ impl Tasks {
tasks: Default::default(), tasks: Default::default(),
properties: vec![ properties: vec![
"state".into(), "state".into(),
"ttime".into(), "rtime".into(),
"rpath".into(), "rpath".into(),
"tags".into(), "tags".into(),
"desc".into(), "desc".into(),
@ -192,7 +192,10 @@ impl Tasks {
self.traverse_up_from(Some(task.event.id)) self.traverse_up_from(Some(task.event.id))
.take_while(|t| Some(t.event.id) != self.position) .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()), prop => task.get(prop).unwrap_or(String::new()),
}) })
.collect::<Vec<String>>() .collect::<Vec<String>>()