summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-08-04 22:01:07 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-08-04 22:01:07 +0200
commitbcd5944116f912e06d4a4528eac7d330196c994c (patch)
tree6df919d12a8fb9d694f6befc8dc178e1e145120f
parent75c238343b8868bc7ff060bee6c99f2d30faee3b (diff)
downloadmoney-bcd5944116f912e06d4a4528eac7d330196c994c.tar.gz
today()
-rw-r--r--cli/src/search.rs11
1 files changed, 7 insertions, 4 deletions
diff --git a/cli/src/search.rs b/cli/src/search.rs
index 972913f..c01e9c6 100644
--- a/cli/src/search.rs
+++ b/cli/src/search.rs
@@ -46,7 +46,7 @@ impl DateIsh {
pub fn get(self) -> NaiveDate {
match self {
DateIsh::Absolute(date) => date,
- DateIsh::Relative(offset) => chrono::offset::Local::today().naive_utc() + offset,
+ DateIsh::Relative(offset) => today() + offset,
}
}
}
@@ -156,6 +156,10 @@ impl Constraint {
}
}
+fn today() -> NaiveDate {
+ chrono::Local::today().naive_utc()
+}
+
fn filter_between(start: NaiveDate, end: NaiveDate) -> Vec<Filter> {
vec![
Filter::Intersect(Constraint::After(DateIsh::Absolute(start))),
@@ -164,7 +168,7 @@ fn filter_between(start: NaiveDate, end: NaiveDate) -> Vec<Filter> {
}
fn this_week() -> Vec<Filter> {
- let today = chrono::Local::today().naive_utc();
+ let today = today();
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);
@@ -172,8 +176,7 @@ fn this_week() -> Vec<Filter> {
}
fn this_month() -> Vec<Filter> {
- let today = chrono::Local::today().naive_utc();
- let start_of_month = today.with_day(1).unwrap();
+ let start_of_month = today().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).unwrap().with_month(1).unwrap(),
_ => start_of_month.with_month(start_of_month.month() + 1).unwrap(),