From bcd5944116f912e06d4a4528eac7d330196c994c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Wed, 4 Aug 2021 22:01:07 +0200 Subject: today() --- cli/src/search.rs | 11 +++++++---- 1 file 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 { vec![ Filter::Intersect(Constraint::After(DateIsh::Absolute(start))), @@ -164,7 +168,7 @@ fn filter_between(start: NaiveDate, end: NaiveDate) -> Vec { } fn this_week() -> Vec { - 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 { } fn this_month() -> Vec { - 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(), -- cgit v1.2.1