forked from janek/mostr
1
0
Fork 0

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.
This commit is contained in:
xeruf 2024-11-08 11:30:08 +01:00
parent baf93bd788
commit 2053f045b2
4 changed files with 47 additions and 17 deletions

44
DESIGN.md Normal file
View File

@ -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.

View File

@ -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)

View File

@ -118,7 +118,7 @@ pub fn format_as_datetime<F>(stamp: &Timestamp, formatter: F) -> String
where
F: Fn(DateTime<Local>) -> 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),
}
}
}

View File

@ -865,6 +865,7 @@ impl TasksRelay {
pub(crate) fn track_at(&mut self, mut time: Timestamp, target: Option<EventId>) -> Option<EventId> {
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() {