From d8eebcfb6ac39f0b44c8b85c4e4fb0d2cf62233c Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Fri, 18 Oct 2024 18:13:35 +0200 Subject: [PATCH] feat(tasks): filter out tracked intervals smaller than 2mins --- src/tasks.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/tasks.rs b/src/tasks.rs index 5351241..2b7de2b 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -255,6 +255,7 @@ impl TasksRelay { .map(|str| EventId::from_str(str).ok().map_or(str.to_string(), |id| self.get_task_path(Some(id)))) .join(" ")); if new != last { + // TODO omit intervals <2min - but I think I need threeway for that // TODO alternate color with grey between days full.push(format!("{} {}", format_timestamp_local(&event.created_at), new.as_ref().unwrap_or(&"---".to_string()))); last = new; @@ -274,10 +275,13 @@ impl TasksRelay { let mut vec = Vec::with_capacity(set.len() / 2); let mut iter = timestamps(set.values(), &ids).tuples(); while let Some(((start, _), (end, _))) = iter.next() { - vec.push(format!("{} - {} by {}", - format_timestamp_local(start), - format_timestamp_relative_to(end, start), - self.get_username(key))) + // Filter out intervals <2 mins + if start.as_u64() + 120 < end.as_u64() { + vec.push(format!("{} - {} by {}", + format_timestamp_local(start), + format_timestamp_relative_to(end, start), + self.get_username(key))) + } } iter.into_buffer() .for_each(|(stamp, _)| @@ -1266,6 +1270,7 @@ fn referenced_event(event: &Event) -> Option<&EventId> { referenced_events(event).next() } +/// Returns the id of a referenced event if it is contained in the provided ids list. fn matching_tag_id<'a>(event: &'a Event, ids: &'a [&'a EventId]) -> Option<&'a EventId> { referenced_events(event).find(|id| ids.contains(id)) }