diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-08-04 21:42:01 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-08-04 21:42:01 +0200 |
| commit | 8dcdd9d9ddb624dbce98ee9e1b53a2988e7c7fce (patch) | |
| tree | 9674acdfabe5238f0ac85b2133a5fdb041f87b8c | |
| parent | 560c19a0b5de0d2c846cb5f4d1d65f291f413162 (diff) | |
| download | money-8dcdd9d9ddb624dbce98ee9e1b53a2988e7c7fce.tar.gz | |
add week bucket
| -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 |
