diff options
Diffstat (limited to 'karld/src/condition.rs')
-rw-r--r-- | karld/src/condition.rs | 44 |
1 files changed, 38 insertions, 6 deletions
diff --git a/karld/src/condition.rs b/karld/src/condition.rs index 1a9abab..643ca5e 100644 --- a/karld/src/condition.rs +++ b/karld/src/condition.rs @@ -1,6 +1,9 @@ use chrono::{Datelike, Duration, NaiveDate, NaiveDateTime, NaiveTime, Timelike}; use karlcommon::{Condition, Property}; -use std::cmp::{max, min}; +use std::{ + cmp::{max, min}, + ops::Range, +}; use Direction::*; use Edge::*; @@ -40,6 +43,12 @@ pub trait ConditionFind { (None, None) => None, } } + + fn find_instance(&self, dir: Direction, from: NaiveDateTime) -> Range<Option<NaiveDateTime>> { + let start = self.find(Edge::Start, dir, from); + let end = self.find(Edge::End, dir, start.unwrap_or(from)); + start..end + } } impl ConditionFind for Condition { @@ -240,11 +249,34 @@ impl ConditionFind for Condition { } } Condition::Range { - prop: _, - min: _, - max: _, - modulus: _, - } => todo!(), + prop, + min, + max, + modulus, + } => { + // TODO + assert_eq!(*modulus, None); + assert_eq!(*prop, Property::Unix); + assert_eq!(dir, Direction::Forward); + let min = NaiveDateTime::from_timestamp(*min, 0); + let max = NaiveDateTime::from_timestamp(*max, 0); + match edge { + Start => { + if min < from { + None + } else { + Some(min) + } + } + End => { + if max < from { + None + } else { + Some(max) + } + } + } + } } } } |