enhance(main): track relatively with @

This commit is contained in:
xeruf 2025-01-21 22:54:23 +01:00
parent 828114f5de
commit eb1bafad2d
2 changed files with 9 additions and 6 deletions

View file

@ -95,6 +95,7 @@ pub fn parse_tracking_stamp(str: &str, after: Option<DateTime<Local>>) -> Option
}
let stripped = str.trim().trim_start_matches('+').trim_start_matches("in ");
if let Ok(num) = stripped.parse::<i64>() {
// 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| {

View file

@ -358,12 +358,14 @@ 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))) {
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.to_timestamp());
tasks.custom_time = Some(time);
}
}
}