From 931edec4a4465150e75f7d77f0e4f607f589bf84 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 15 May 2024 23:15:09 -0400 Subject: [PATCH] wip --- pttodoer/src/main.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/pttodoer/src/main.rs b/pttodoer/src/main.rs index fb9af62..0c29fb1 100644 --- a/pttodoer/src/main.rs +++ b/pttodoer/src/main.rs @@ -1,5 +1,5 @@ use serde_yaml; -use chrono::DateTime; +use chrono::{DateTime, Local}; use chrono::naive::NaiveDateTime; use regex::Regex; use croner; @@ -21,8 +21,29 @@ impl Task { } fn is_due(&self) -> bool { - assert!(false); - false + self.is_due_now(TS::now()) + } + + 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 { @@ -279,6 +300,10 @@ mod test_duration { struct TS(u64); impl TS { + fn now() -> TS { + Self::from_unix(Local::now().timestamp() as u64) + } + fn from_unix(src: u64) -> TS { TS{0: src} }