From 5d78b091c40157386fac2f0ee0d517ccbaff4a1e Mon Sep 17 00:00:00 2001 From: Joscha Date: Tue, 14 Dec 2021 23:50:03 +0100 Subject: [PATCH] Fix range calculation for date formulas --- src/eval/command/formula.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/eval/command/formula.rs b/src/eval/command/formula.rs index 0e81ca3..9f5b6de 100644 --- a/src/eval/command/formula.rs +++ b/src/eval/command/formula.rs @@ -1,4 +1,4 @@ -use chrono::{Datelike, NaiveDate}; +use chrono::{Datelike, Duration, NaiveDate}; use crate::files::commands::{self, Command}; use crate::files::primitives::{Span, Spanned, Time, Weekday}; @@ -328,8 +328,14 @@ impl FormulaSpec { if let Command::Task(_) = s.command.command { if let Some(last_done_root) = s.last_done_root() { range = range.with_from(last_done_root.succ())?; + } else if let Some(from) = s.from { + range = range.with_from(from)?; + } else if matches!(s.command.command, Command::Task(_)) { + // We have no idea if we missed any tasks since the user hasn't + // specified a `FROM`, so we just just look back one year. Any + // task older than a year is probably not important anyways... + range = range.with_from(range.from() - Duration::days(365))?; } - // TODO Otherwise, go back one year or so if no FROM is specified } s.limit_from_until(range)