From 16392861893183d2394d27851a8e9499b0ab71a0 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 15 May 2024 23:27:03 -0400 Subject: [PATCH] so close tho --- pttodoer/src/main.rs | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/pttodoer/src/main.rs b/pttodoer/src/main.rs index 73213c0..8ed1ed8 100644 --- a/pttodoer/src/main.rs +++ b/pttodoer/src/main.rs @@ -26,7 +26,10 @@ impl Task { fn is_due_now(&self, now: TS) -> bool { match self.when() { - Some(when) => now.unix() <= when.next(self.ts()).unix(), + Some(when) => { + eprintln!("next: {}", when.next(self.ts()).to_string()); + now.unix() <= when.next(self.ts()).unix() + }, None => true, } } @@ -35,7 +38,10 @@ impl Task { match self.get("schedule".to_string()) { Some(v) => match When::new(v) { Ok(when) => Some(when), - Err(_) => None, + Err(msg) => { + eprintln!("Task.when(): {}", msg); + return None; + }, }, None => None, } @@ -55,9 +61,12 @@ impl Task { match self.0.get(k) { Some(v) => Some( serde_yaml::to_string(v) - .unwrap() - .trim() - .to_string() + .unwrap() + .to_string() + .trim() + .trim_start_matches('\'') + .trim_end_matches( '\'') + .to_string() ), None => None, } @@ -84,6 +93,17 @@ mod test_task { Some("v".to_string()), ); } + + #[test] + fn is_due() { + let mut t = Task::new(); + assert!(t.is_due()); + t.set("ts".to_string(), "61".to_string()); + t.set("schedule".to_string(), "* * * * *".to_string()); + assert!(!t.is_due_now(TS::from_unix(119))); + assert!(t.is_due_now(TS::from_unix(120))); + assert!(t.is_due_now(TS::from_unix(121))); + } } #[derive(Debug)] @@ -103,7 +123,7 @@ impl When { Some(x) => { return Ok(x); }, None => {}, }; - Err(format!("cannot parse when {}", src)) + Err(format!("cannot parse when: {}", src)) } fn new_duration(src: String) -> Option { @@ -228,6 +248,10 @@ mod test_cron { #[test] fn parse() { + match Cron::new("* * * * *".to_string()) { + Ok(c) => {} + Err(err) => assert!(false, "failed to parse cron: {}", err), + }; match Cron::new("1 * * * *".to_string()) { Ok(c) => assert_eq!(1714525200+60, c.next(TS::from_unix(1714525200)).unix()), Err(err) => assert!(false, "failed to parse cron: {}", err),