diff --git a/pttodoest/src/main.rs b/pttodoest/src/main.rs index 4229c48..7c4aad6 100755 --- a/pttodoest/src/main.rs +++ b/pttodoest/src/main.rs @@ -20,12 +20,15 @@ fn main() { Some(add_schedule) => { let mut m = serde_yaml::Mapping::new(); m.insert("schedule".into(), add_schedule.into()); - m.insert("todo".into(), add.into()); + m.insert("do".into(), add.into()); Task(serde_yaml::Value::Mapping(m)) } }; files.files[0] - .append(Delta::add(task)) + .append(match task.next_due(Delta::now_time()) { + None => Delta::add(task), + Some(due) => Delta::add_at(task, due), + }) .expect("failed to add"); files.files[0] .stage_persisted() @@ -198,7 +201,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(), now))?; + self.append(Delta::add_at(before.clone(), due))?; } } } @@ -414,7 +417,9 @@ mod test_file { {{"ts":2, "op":"Add", "task": "old"}} {{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}} {{"ts":{}, "op":"Add", "task": "persisted but not snapshotted"}} + {{"ts":{}, "op":"Add", "task": "doesnt exist yet"}} "#, + Delta::now_time() - 50, Delta::now_time() + 50, ) .as_str(), @@ -422,14 +427,14 @@ mod test_file { let f = File::new(&d.path().join("plain").to_str().unwrap().to_string()); - assert_eq!(4, f.events().unwrap().0.len()); + assert_eq!(5, f.events().unwrap().0.len()); assert_eq!(2, f.stage().unwrap().len()); tests::file_contains(&d, "plain", "old"); tests::file_contains(&d, "plain", "new"); f.persist_stage().unwrap(); assert_eq!( - 6, + 7, f.events().unwrap().0.len(), "events: {:?}", f.events().unwrap() @@ -439,7 +444,7 @@ mod test_file { f.stage_persisted().unwrap(); assert_eq!( - 7, + 8, f.events().unwrap().0.len(), "{:?}", f.events().unwrap().0 @@ -502,7 +507,7 @@ mod test_file { {{"ts":1, "op":"Add", "task": "stage"}} {{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}} "#, - Delta::now_time() + 50, + //Delta::now_time() + 50, ) .as_str(), ); @@ -877,7 +882,7 @@ impl Events { fn snapshot(&self) -> Result, String> { let mut result = vec![]; - for event in self.0.iter() { + for event in self.0.iter().filter(|t| t.ts <= Delta::now_time()) { match &event.op { Op::Add => match event.task.next_due(event.ts) { Some(next_due) => match next_due <= Delta::now_time() {