From 7e3039ef1aa683fbb9a76225f1aabc3e3df2f085 Mon Sep 17 00:00:00 2001 From: xeruf <27jf@pm.me> Date: Sat, 25 Jan 2025 06:42:41 +0100 Subject: [PATCH] enhance(main): adapt relative timestamp parsing to allow backdating for recent hours --- src/main.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9445346..3dd94ad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use crate::kinds::{format_tag_basic, match_event_tag, Prio, BASIC_KINDS, PROPERT use crate::task::{State, StateChange, Task, MARKER_PROPERTY}; use crate::tasks::{referenced_event, PropertyCollection, StateFilter, TasksRelay}; -use chrono::{DateTime, Local, TimeZone, Utc}; +use chrono::{DateTime, Local, TimeDelta, TimeZone, Utc}; use colored::Colorize; use directories::ProjectDirs; use env_logger::{Builder, Target, WriteStyle}; @@ -27,6 +27,7 @@ use std::fs; use std::fs::File; use std::io::{BufRead, BufReader, Write}; use std::iter::once; +use std::ops::Add; use std::path::PathBuf; use std::str::FromStr; use std::time::Duration; @@ -364,8 +365,8 @@ async fn main() -> Result<()> { if let Some((left, arg)) = command.split_once("@") { 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) { + 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))) { command = left.to_string(); tasks.custom_time = Some(time); }