summaryrefslogtreecommitdiffstats
path: root/cli/src/search.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/src/search.rs')
-rw-r--r--cli/src/search.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/cli/src/search.rs b/cli/src/search.rs
index d388a8b..54eea67 100644
--- a/cli/src/search.rs
+++ b/cli/src/search.rs
@@ -27,7 +27,30 @@ impl Constraint {
fn satisfies(&self, t: &Transaction) -> bool {
match self {
Constraint::Category(category) => category == &t.category,
- Constraint::Date(_) => todo!(),
+ Constraint::Date(DateFilter::Relative {
+ start,
+ end,
+ }) => {
+ if let (Some(start), Some(end)) = (start, end) {
+ assert!(start < end);
+ }
+ let now = chrono::offset::Local::today().naive_utc();
+ let start_valid = start.map(|start| t.date > now + start).unwrap_or(true);
+ let end_valid = end.map(|end| t.date < now + end).unwrap_or(true);
+ start_valid && end_valid
+ },
+ Constraint::Date(DateFilter::Absolute {
+ start,
+ end,
+ }) => {
+ if let (Some(start), Some(end)) = (start, end) {
+ assert!(start < end);
+ }
+ let now = chrono::offset::Local::today().naive_utc();
+ let start_valid = start.map(|start| t.date > start).unwrap_or(true);
+ let end_valid = end.map(|end| t.date < end).unwrap_or(true);
+ start_valid && end_valid
+ },
}
}
}