summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-08-04 21:42:01 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-08-04 21:42:01 +0200
commit8dcdd9d9ddb624dbce98ee9e1b53a2988e7c7fce (patch)
tree9674acdfabe5238f0ac85b2133a5fdb041f87b8c
parent560c19a0b5de0d2c846cb5f4d1d65f291f413162 (diff)
downloadmoney-8dcdd9d9ddb624dbce98ee9e1b53a2988e7c7fce.tar.gz
add week bucket
-rw-r--r--cli/src/search.rs16
-rw-r--r--cli/todo2
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('"')),
diff --git a/cli/todo b/cli/todo
index 46ef985..b4e2cff 100644
--- a/cli/todo
+++ b/cli/todo
@@ -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