From 2053f045b231424a9dc0f17806bf2600ec845a3b Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Fri, 8 Nov 2024 11:30:08 +0100 Subject: [PATCH] fix(helpers): add one second to displayed timestamp to produce round times on stopping Internally, tracking is stopped one second earlier to prevent random accidental overlaps. This brings the interface in line with the user input. --- DESIGN.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 15 --------------- src/helpers.rs | 4 ++-- src/tasks.rs | 1 + 4 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 DESIGN.md diff --git a/DESIGN.md b/DESIGN.md new file mode 100644 index 0000000..86f9c26 --- /dev/null +++ b/DESIGN.md @@ -0,0 +1,44 @@ +# Mostr Design & Internals + +## Nostr Reference + +All used nostr kinds are listed on the top of [kinds.rs](./src/kinds.rs) + +Mostr mainly uses the following NIPs: + +- Kind 1 for task descriptions and permanent tasks, can contain task property updates (tags, priority) +- Issue Tracking: https://github.com/nostr-protocol/nips/blob/master/34.md + + Tasks have Kind 1621 (originally: git issue - currently no markdown support implemented) + + TBI: Kind 1622 for task comments + + Kind 1630-1633: Task Status (1630 Open, 1631 Done, 1632 Closed, 1633 Pending) +- Own Kind 1650 for time-tracking + +Considering to use Calendar: https://github.com/nostr-protocol/nips/blob/master/52.md + +- Kind 31922 for GANTT, since it has only Date +- Kind 31923 for Calendar, since it has a time + +## Immutability + +Apart from user-specific temporary utilities such as the Bookmark List (Kind 10003), +all shared data is immutable, and modifications are recorded as separate events, +providing full audit security. +Deletions are not considered. + +### Timestamps + +Mostr provides convenient helpers to backdate an action to a limited extent. +But when closing one task with `)10` at 10:00 of the current day +and starting another with `(10` on the same day, +depending on the order of the event ids, +the started task would be terminated immediately +due to the equal timestamp. + +That is why I decided to subtract one second from the timestamp +whenever timetracking is stopped, +making sure that the stop event always happens before the start event +when the same timestamp is provided in the interface. +Since the user interface is anyways focused on comprehensible output +and thus slightly fuzzy, +I then also add one second to each timestamp displayed +to make the displayed timestamps more intuitive. \ No newline at end of file diff --git a/README.md b/README.md index 838191e..2298ab6 100644 --- a/README.md +++ b/README.md @@ -142,21 +142,6 @@ An active tag or status filter will also set that attribute for newly created ta - TBI = To Be Implemented - `. TASK` - create and enter a new task even if the name matches an existing one -## Nostr reference - -Mostr mainly uses the following NIPs: - -- Kind 1 for task descriptions and permanent tasks, can contain task property updates (tags, priority) -- Issue Tracking: https://github.com/nostr-protocol/nips/blob/master/34.md - + Tasks have Kind 1621 (originally: git issue - currently no markdown support implemented) - + TBI: Kind 1622 for task comments - + Kind 1630-1633: Task Status (1630 Open, 1631 Done, 1632 Closed, 1633 Pending) -- Own Kind 1650 for time-tracking - -Considering to use Calendar: https://github.com/nostr-protocol/nips/blob/master/52.md -- Kind 31922 for GANTT, since it has only Date -- Kind 31923 for Calendar, since it has a time - ## Plans - Handle event sending rejections (e.g. permissions) diff --git a/src/helpers.rs b/src/helpers.rs index 7e08bde..9693587 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -118,7 +118,7 @@ pub fn format_as_datetime(stamp: &Timestamp, formatter: F) -> String where F: Fn(DateTime) -> String, { - match Local.timestamp_opt(stamp.as_u64() as i64, 0) { + match Local.timestamp_opt(stamp.as_u64() as i64 + 1, 0) { Single(time) => formatter(time), _ => stamp.to_human_datetime(), } @@ -149,4 +149,4 @@ pub fn format_timestamp_relative_to(stamp: &Timestamp, reference: &Timestamp) -> -3..=3 => format_timestamp(stamp, "%a %H:%M"), _ => format_timestamp_local(stamp), } -} \ No newline at end of file +} diff --git a/src/tasks.rs b/src/tasks.rs index 2b7de2b..3d10f99 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -865,6 +865,7 @@ impl TasksRelay { pub(crate) fn track_at(&mut self, mut time: Timestamp, target: Option) -> Option { if target.is_none() { + // Prevent random overlap with tracking started in the same second time = time - 1; } else if let Some(hist) = self.history.get(&self.sender.pubkey()) { while hist.get(&time).is_some() {