summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-08-04 23:54:12 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-08-04 23:54:12 +0200
commitbc60d325c6da8128d2ba9dc6ac3f9794528a1cab (patch)
tree9241f8588bdfc4040097e5f53ec5034af2efd2ed
parenta966c8038820ee29cc6c6c9ebfe47045b30aa124 (diff)
downloadmoney-bc60d325c6da8128d2ba9dc6ac3f9794528a1cab.tar.gz
this_x -> x_of
-rw-r--r--cli/src/search.rs15
1 files 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<Filter> {
]
}
-fn this_week() -> Vec<Filter> {
- 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<Filter> {
+ 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<Filter> {
- let start_of_month = today().with_day(1).unwrap();
+fn month_of(date: NaiveDate) -> Vec<Filter> {
+ 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)