From 09ee50601311c802e67e1f7b0a5278c334d2e406 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Tue, 14 Jun 2022 13:58:09 +0200 Subject: dynamic scheduling --- karld/src/condition.rs | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'karld/src/condition.rs') 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> { + 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) + } + } + } + } } } } -- cgit v1.2.3-70-g09d2