From 72eb29d7669cb4a727a47c8acc08f0b81d6e5a17 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Thu, 20 Nov 2025 14:29:01 -0700 Subject: [PATCH] step 1 --- pttodoest/src/main.rs | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/pttodoest/src/main.rs b/pttodoest/src/main.rs index 7fa9339..3b09fe7 100755 --- a/pttodoest/src/main.rs +++ b/pttodoest/src/main.rs @@ -234,7 +234,7 @@ impl File { let now = Delta::now_time(); if let Some(due) = before.next_due(now.clone()) { if due >= now { - self.append(Delta::add_at(before.clone(), due))?; + self.append(Delta::add_at(before.clone(), now))?; } } } @@ -589,12 +589,14 @@ struct Delta { ts: u64, op: Op, task: Task, + tasks: Option>, } #[derive(Debug, Clone, Serialize, Deserialize)] enum Op { Add, Remove, + Snapshot, } impl Delta { @@ -603,6 +605,7 @@ impl Delta { ts: ts, op: op, task: task, + tasks: None, } } @@ -842,7 +845,7 @@ impl Events { fn snapshot(&self) -> Result, String> { let mut result = vec![]; for event in self.0.iter() { - match event.op { + match &event.op { Op::Add => match event.task.next_due(event.ts) { Some(next_due) => match next_due <= Delta::now_time() { true => result.push(event.task.clone()), @@ -863,6 +866,7 @@ impl Events { } } } + Op::Snapshot => result = event.tasks.clone().unwrap(), }; } Ok(result) @@ -873,6 +877,31 @@ impl Events { mod test_events { use super::*; + #[test] + fn test_events_op_snapshot() { + tests::with_dir(|d| { + tests::write_file(&d, "plain", "- who cares"); + tests::write_file( + &d, + ".plain.some_host", + r#" + {"ts":1, "op":"Snapshot", "task":"", "tasks":["snapshotted"]} + "#, + ); + + let events = + Events::new(&d.path().join("plain").to_str().unwrap().to_string()).unwrap(); + assert_eq!(1, events.0.len(), "events: {:?}", events); + + let snapshot = events.snapshot().unwrap(); + assert_eq!(1, snapshot.len()); + assert_eq!( + serde_yaml::Value::String("snapshotted".to_string()), + snapshot[0].0 + ); + }); + } + #[test] fn test_events_oplog_to_snapshot_one() { tests::with_dir(|d| {