From c06091d576c91c00283835f7b9acb0523cff123d Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Wed, 12 Nov 2025 14:44:35 -0700 Subject: [PATCH] test schedule can pass --- pttodoest/src/main.rs | 54 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/pttodoest/src/main.rs b/pttodoest/src/main.rs index e878779..a497a27 100755 --- a/pttodoest/src/main.rs +++ b/pttodoest/src/main.rs @@ -205,6 +205,11 @@ impl File { for before in before.iter() { if !after.contains(before) { self.append(Delta::remove_at(before.clone(), now))?; + if let Some(due) = before.next_due(Delta::now_time()) { + if due >= Delta::now_time() { + self.append(Delta::add_at(before.clone(), due))?; + } + } } } for after in after.iter() { @@ -422,7 +427,7 @@ mod test_file { {{"ts":2, "op":"Add", "task": "old"}} {{"ts":{}, "op":"Add", "task": "enqueued for persistence"}} "#, - 2147483647, + Delta::now_time() + 5, ) .as_str(), ); @@ -453,6 +458,45 @@ mod test_file { tests::file_contains(&d, "plain", "old"); }); } + + #[test] + fn test_schedule_date_future() { + tests::with_dir(|d| { + tests::write_file(&d, "plain", "[]"); + let f = File::new(&d.path().join("plain").to_str().unwrap().to_string()); + + let mut m = serde_yaml::Mapping::new(); + m.insert("schedule".into(), "2036-01-02".into()); + let task = Task(serde_yaml::Value::Mapping(m)); + + f.append(Delta::add(task)).unwrap(); + assert_eq!( + 1, + f.events().unwrap().0.len(), + "{:?}", + f.events().unwrap().0 + ); + assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); + + f.persist_stage().unwrap(); + assert_eq!( + 1, + f.events().unwrap().0.len(), + "{:?}", + f.events().unwrap().0 + ); + assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); + + f.stage_persisted().unwrap(); + assert_eq!( + 1, + f.events().unwrap().0.len(), + "{:?}", + f.events().unwrap().0 + ); + assert_eq!(0, f.stage().unwrap().len(), "{:?}", f.stage()); + }); + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -714,7 +758,13 @@ impl Events { let mut result = vec![]; for event in self.0.iter() { match event.op { - Op::Add => result.push(event.task.clone()), + Op::Add => match event.task.next_due(event.ts) { + Some(next_due) => match next_due <= Delta::now_time() { + true => result.push(event.task.clone()), + false => {} + }, + None => result.push(event.task.clone()), + }, Op::Remove => { let mut i = (result.len() - 1) as i32; while i >= 0 {