From bc60d325c6da8128d2ba9dc6ac3f9794528a1cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 4 Aug 2021 23:54:12 +0200 Subject: this_x -> x_of --- cli/src/search.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/src/search.rs b/cli/src/search.rs index 7ca6a29..1febc83 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -143,8 +143,8 @@ impl Constraint { preceded(tag("amount:"), parse_comparison), |(amount, comparison)| Constraint::AmountCompare(amount, comparison), ), - map(tag("week"), |_| Constraint::Filters(this_week())), - map(tag("month"), |_| Constraint::Filters(this_month())), + map(tag("week"), |_| Constraint::Filters(week_of(today()))), + map(tag("month"), |_| Constraint::Filters(month_of(today()))), map( delimited(char('('), separated_list0(space1, Filter::parse), char(')')), Constraint::Filters, @@ -164,16 +164,15 @@ fn filter_between(start: NaiveDate, end: NaiveDate) -> Vec { ] } -fn this_week() -> Vec { - let today = today(); - let to_last_monday = Duration::days(today.weekday().num_days_from_monday() as i64); - let last_monday = today - to_last_monday; +fn week_of(date: NaiveDate) -> Vec { + let to_last_monday = Duration::days(date.weekday().num_days_from_monday() as i64); + let last_monday = date - to_last_monday; let next_monday = last_monday + Duration::weeks(1); filter_between(last_monday, next_monday) } -fn this_month() -> Vec { - let start_of_month = today().with_day(1).unwrap(); +fn month_of(date: NaiveDate) -> Vec { + let start_of_month = date.with_day(1).unwrap(); let start_of_next_month = match start_of_month.month() { 12 => start_of_month .with_year(start_of_month.year() + 1) -- cgit v1.2.1