forked from janek/mostr
enhance: use adaptive relative timestamp parsing for )
This commit is contained in:
parent
7e3039ef1a
commit
cbeba49bb3
2 changed files with 9 additions and 7 deletions
|
@ -364,9 +364,7 @@ async fn main() -> Result<()> {
|
||||||
Some(_) =>
|
Some(_) =>
|
||||||
if let Some((left, arg)) = command.split_once("@") {
|
if let Some((left, arg)) = command.split_once("@") {
|
||||||
if !arg.contains(|s: char| s.is_alphabetic()) {
|
if !arg.contains(|s: char| s.is_alphabetic()) {
|
||||||
let pos = tasks.get_position_timestamped();
|
if let Some(time) = tasks.parse_tracking_stamp_relative(arg) {
|
||||||
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();
|
command = left.to_string();
|
||||||
tasks.custom_time = Some(time);
|
tasks.custom_time = Some(time);
|
||||||
}
|
}
|
||||||
|
@ -685,9 +683,7 @@ async fn main() -> Result<()> {
|
||||||
match arg {
|
match arg {
|
||||||
None => tasks.move_to(None),
|
None => tasks.move_to(None),
|
||||||
Some(arg) => {
|
Some(arg) => {
|
||||||
let pos = tasks.get_position_timestamped();
|
if tasks.parse_tracking_stamp_relative(arg)
|
||||||
let time = pos.1.and_then(|_| Local.timestamp_opt(pos.0.as_u64() as i64, 0).earliest());
|
|
||||||
if parse_tracking_stamp(arg, time)
|
|
||||||
.and_then(|stamp| tasks.track_at(stamp, None)).is_some() {
|
.and_then(|stamp| tasks.track_at(stamp, None)).is_some() {
|
||||||
println!("{}", tasks.times_tracked(15));
|
println!("{}", tasks.times_tracked(15));
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ use crate::tasks::children_traversal::ChildrenTraversal;
|
||||||
use crate::tasks::durations::{referenced_events, timestamps, Durations};
|
use crate::tasks::durations::{referenced_events, timestamps, Durations};
|
||||||
pub use crate::tasks::nostr_users::NostrUsers;
|
pub use crate::tasks::nostr_users::NostrUsers;
|
||||||
|
|
||||||
use chrono::{Local, TimeDelta};
|
use chrono::{Local, TimeDelta, TimeZone};
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
|
@ -242,6 +242,12 @@ impl TasksRelay {
|
||||||
self.get_position_at(now())
|
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 {
|
fn sorting_key(&self, task: &Task) -> impl Ord {
|
||||||
self.sorting
|
self.sorting
|
||||||
.iter()
|
.iter()
|
||||||
|
|
Loading…
Add table
Reference in a new issue