feat(tasks): interpret plain numbers as minutes and strip prefixes

This commit is contained in:
xeruf 2024-08-15 13:16:14 +03:00
parent 9c0a688297
commit 92b4be130c
1 changed files with 6 additions and 1 deletions

View File

@ -702,7 +702,12 @@ impl Tasks {
/// Returns false and prints a message if parsing failed
pub(crate) fn track_from(&mut self, str: &str) -> bool {
// Using two libraries for better exhaustiveness, see https://github.com/uutils/parse_datetime/issues/84
match interim::parse_date_string(&str, Local::now(), interim::Dialect::Uk) {
let stripped = str.trim().trim_start_matches('+').trim_start_matches("in ");
if let Ok(num) = stripped.parse::<i64>() {
self.track_at(Timestamp::from(Timestamp::now().as_u64().saturating_add_signed(num * 60)));
return true
}
match interim::parse_date_string(stripped, Local::now(), interim::Dialect::Us) {
Ok(date) => Some(date.to_utc()),
Err(e) => {
match parse_datetime::parse_datetime_at_date(Local::now(), str) {