diff options
author | metamuffin <yvchraiqi@protonmail.com> | 2022-06-14 13:58:09 +0200 |
---|---|---|
committer | metamuffin <yvchraiqi@protonmail.com> | 2022-06-14 13:58:09 +0200 |
commit | 09ee50601311c802e67e1f7b0a5278c334d2e406 (patch) | |
tree | 12325eda3288e08c16ffd85cce0aaa3ff4344be9 /karld/src/condition.rs | |
parent | a7abc26af31b69db06a5875fc3fbc756adc838b1 (diff) | |
download | karlender-09ee50601311c802e67e1f7b0a5278c334d2e406.tar karlender-09ee50601311c802e67e1f7b0a5278c334d2e406.tar.bz2 karlender-09ee50601311c802e67e1f7b0a5278c334d2e406.tar.zst |
dynamic scheduling
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) + } + } + } + } } } } |