enhance: use adaptive relative timestamp parsing for )

This commit is contained in:
xeruf 2025-01-25 06:44:08 +01:00
parent 7e3039ef1a
commit cbeba49bb3
2 changed files with 9 additions and 7 deletions

View file

@ -364,9 +364,7 @@ async fn main() -> Result<()> {
Some(_) =>
if let Some((left, arg)) = command.split_once("@") {
if !arg.contains(|s: char| s.is_alphabetic()) {
let pos = tasks.get_position_timestamped();
let mut pos_time = pos.1.and_then(|_| Local.timestamp_opt(pos.0.as_u64() as i64, 0).earliest());
if let Some(time) = parse_tracking_stamp(arg, pos_time.take_if(|t| Local::now() - *t > TimeDelta::hours(6))) {
if let Some(time) = tasks.parse_tracking_stamp_relative(arg) {
command = left.to_string();
tasks.custom_time = Some(time);
}
@ -685,9 +683,7 @@ async fn main() -> Result<()> {
match arg {
None => tasks.move_to(None),
Some(arg) => {
let pos = tasks.get_position_timestamped();
let time = pos.1.and_then(|_| Local.timestamp_opt(pos.0.as_u64() as i64, 0).earliest());
if parse_tracking_stamp(arg, time)
if tasks.parse_tracking_stamp_relative(arg)
.and_then(|stamp| tasks.track_at(stamp, None)).is_some() {
println!("{}", tasks.times_tracked(15));
}

View file

@ -16,7 +16,7 @@ use crate::tasks::children_traversal::ChildrenTraversal;
use crate::tasks::durations::{referenced_events, timestamps, Durations};
pub use crate::tasks::nostr_users::NostrUsers;
use chrono::{Local, TimeDelta};
use chrono::{Local, TimeDelta, TimeZone};
use colored::Colorize;
use itertools::Itertools;
use log::{debug, error, info, trace, warn};
@ -242,6 +242,12 @@ impl TasksRelay {
self.get_position_at(now())
}
pub(super) fn parse_tracking_stamp_relative(&self, input: &str) -> Option<Timestamp> {
let pos = self.get_position_timestamped();
let mut pos_time = pos.1.and_then(|_| Local.timestamp_opt(pos.0.as_u64() as i64, 0).earliest());
parse_tracking_stamp(input, pos_time.take_if(|t| Local::now() - *t > TimeDelta::hours(6)))
}
fn sorting_key(&self, task: &Task) -> impl Ord {
self.sorting
.iter()