From eb1bafad2da6c53e6f5dcf5556156be310850eea Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Tue, 21 Jan 2025 22:54:23 +0100 Subject: [PATCH] enhance(main): track relatively with @ --- src/helpers.rs | 1 + src/main.rs | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/helpers.rs b/src/helpers.rs index 3f5b897..0ec49a6 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -95,6 +95,7 @@ pub fn parse_tracking_stamp(str: &str, after: Option>) -> Option } let stripped = str.trim().trim_start_matches('+').trim_start_matches("in "); if let Ok(num) = stripped.parse::() { + // Complication needed because timestamp can only add u64, but we also want reverse return Some(Timestamp::from(Timestamp::now().as_u64().saturating_add_signed(num * 60))); } parse_date(str).and_then(|time| { diff --git a/src/main.rs b/src/main.rs index c378b0c..a6476d1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -358,15 +358,17 @@ async fn main() -> Result<()> { continue 'repl; } Some('@') => {} - Some(_) => { + Some(_) => if let Some((left, arg)) = command.split_once("@") { - if let Some(time) = parse_hour(arg, 20) - .or_else(|| parse_date(arg).map(|utc| utc.with_timezone(&Local))) { - command = left.to_string(); - tasks.custom_time = Some(time.to_timestamp()); + if !arg.contains(|s: char| s.is_alphabetic()) { + let pos = tasks.get_position_timestamped(); + let time = pos.1.and_then(|_| Local.timestamp_opt(pos.0.as_u64() as i64, 0).earliest()); + if let Some(time) = parse_tracking_stamp(arg, time) { + command = left.to_string(); + tasks.custom_time = Some(time); + } } } - } } let arg = if command.len() > 1 {