master
Bel LaPointe 2024-05-15 23:15:09 -04:00
parent 4154e1aad8
commit 931edec4a4
1 changed files with 28 additions and 3 deletions

View File

@ -1,5 +1,5 @@
use serde_yaml; use serde_yaml;
use chrono::DateTime; use chrono::{DateTime, Local};
use chrono::naive::NaiveDateTime; use chrono::naive::NaiveDateTime;
use regex::Regex; use regex::Regex;
use croner; use croner;
@ -21,8 +21,29 @@ impl Task {
} }
fn is_due(&self) -> bool { fn is_due(&self) -> bool {
assert!(false); self.is_due_now(TS::now())
false }
fn is_due_now(&self, now: TS) -> bool {
match self.get("schedule".to_string()) {
Some(v) => {
match When::new(v) {
Ok(when) => now.unix() <= when.next(self.ts()).unix(),
Err(_) => true,
}
},
None => true,
}
}
fn ts(&self) -> TS {
match self.get("ts".to_string()) {
Some(v) => match TS::new(v) {
Ok(ts) => ts,
Err(_) => TS::from_unix(0),
},
None => TS::from_unix(0),
}
} }
fn get(&self, k: String) -> Option<String> { fn get(&self, k: String) -> Option<String> {
@ -279,6 +300,10 @@ mod test_duration {
struct TS(u64); struct TS(u64);
impl TS { impl TS {
fn now() -> TS {
Self::from_unix(Local::now().timestamp() as u64)
}
fn from_unix(src: u64) -> TS { fn from_unix(src: u64) -> TS {
TS{0: src} TS{0: src}
} }