diff options
| -rw-r--r-- | cli/src/search.rs | 16 | ||||
| -rw-r--r-- | cli/todo | 2 |
2 files changed, 16 insertions, 2 deletions
diff --git a/cli/src/search.rs b/cli/src/search.rs index 47726a3..fb7f5dc 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -1,3 +1,4 @@ +use chrono::Datelike; use chrono::{naive::NaiveDate, Duration}; use nom::branch::alt; use nom::bytes::complete::{is_not, tag, take}; @@ -140,6 +141,10 @@ impl Constraint { |(amount, comparison)| Constraint::AmountCompare(amount, comparison), ), map( + tag("week"), + |_| Constraint::Filters(this_week()), + ), + map( delimited(char('('), separated_list0(space1, Filter::parse), char(')')), Constraint::Filters, ), @@ -147,6 +152,17 @@ impl Constraint { } } +fn this_week() -> Vec<Filter> { + let today = chrono::Local::today().naive_utc(); + let to_last_monday = Duration::days(today.weekday().num_days_from_monday() as i64); + let last_monday = today - to_last_monday; + let next_monday = last_monday + Duration::weeks(1); + vec![ + Filter::Intersect(Constraint::After(DateIsh::Absolute(last_monday))), + Filter::Intersect(Constraint::Before(DateIsh::Absolute(next_monday))), + ] +} + fn string(i: &str) -> nom::IResult<&str, &str> { alt(( delimited(char('"'), is_not("\""), char('"')), @@ -3,8 +3,6 @@ search / display / count stores > handle to/from differently for expense/income? expense/income - time frames - buckets (this week) group by category by time frame |
