add w schedule via ts after now
parent
fe8a55b4c1
commit
a5553d75f4
|
|
@ -20,12 +20,15 @@ fn main() {
|
||||||
Some(add_schedule) => {
|
Some(add_schedule) => {
|
||||||
let mut m = serde_yaml::Mapping::new();
|
let mut m = serde_yaml::Mapping::new();
|
||||||
m.insert("schedule".into(), add_schedule.into());
|
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))
|
Task(serde_yaml::Value::Mapping(m))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
files.files[0]
|
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");
|
.expect("failed to add");
|
||||||
files.files[0]
|
files.files[0]
|
||||||
.stage_persisted()
|
.stage_persisted()
|
||||||
|
|
@ -198,7 +201,7 @@ impl File {
|
||||||
let now = Delta::now_time();
|
let now = Delta::now_time();
|
||||||
if let Some(due) = before.next_due(now.clone()) {
|
if let Some(due) = before.next_due(now.clone()) {
|
||||||
if due >= now {
|
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":"Add", "task": "old"}}
|
||||||
{{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}}
|
{{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}}
|
||||||
{{"ts":{}, "op":"Add", "task": "persisted but not snapshotted"}}
|
{{"ts":{}, "op":"Add", "task": "persisted but not snapshotted"}}
|
||||||
|
{{"ts":{}, "op":"Add", "task": "doesnt exist yet"}}
|
||||||
"#,
|
"#,
|
||||||
|
Delta::now_time() - 50,
|
||||||
Delta::now_time() + 50,
|
Delta::now_time() + 50,
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
|
|
@ -422,14 +427,14 @@ mod test_file {
|
||||||
|
|
||||||
let f = File::new(&d.path().join("plain").to_str().unwrap().to_string());
|
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());
|
assert_eq!(2, f.stage().unwrap().len());
|
||||||
tests::file_contains(&d, "plain", "old");
|
tests::file_contains(&d, "plain", "old");
|
||||||
tests::file_contains(&d, "plain", "new");
|
tests::file_contains(&d, "plain", "new");
|
||||||
|
|
||||||
f.persist_stage().unwrap();
|
f.persist_stage().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
6,
|
7,
|
||||||
f.events().unwrap().0.len(),
|
f.events().unwrap().0.len(),
|
||||||
"events: {:?}",
|
"events: {:?}",
|
||||||
f.events().unwrap()
|
f.events().unwrap()
|
||||||
|
|
@ -439,7 +444,7 @@ mod test_file {
|
||||||
|
|
||||||
f.stage_persisted().unwrap();
|
f.stage_persisted().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
7,
|
8,
|
||||||
f.events().unwrap().0.len(),
|
f.events().unwrap().0.len(),
|
||||||
"{:?}",
|
"{:?}",
|
||||||
f.events().unwrap().0
|
f.events().unwrap().0
|
||||||
|
|
@ -502,7 +507,7 @@ mod test_file {
|
||||||
{{"ts":1, "op":"Add", "task": "stage"}}
|
{{"ts":1, "op":"Add", "task": "stage"}}
|
||||||
{{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}}
|
{{"ts":2, "op":"Snapshot", "task": null, "tasks": ["removed", "old"]}}
|
||||||
"#,
|
"#,
|
||||||
Delta::now_time() + 50,
|
//Delta::now_time() + 50,
|
||||||
)
|
)
|
||||||
.as_str(),
|
.as_str(),
|
||||||
);
|
);
|
||||||
|
|
@ -877,7 +882,7 @@ impl Events {
|
||||||
|
|
||||||
fn snapshot(&self) -> Result<Vec<Task>, String> {
|
fn snapshot(&self) -> Result<Vec<Task>, String> {
|
||||||
let mut result = vec![];
|
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 {
|
match &event.op {
|
||||||
Op::Add => match event.task.next_due(event.ts) {
|
Op::Add => match event.task.next_due(event.ts) {
|
||||||
Some(next_due) => match next_due <= Delta::now_time() {
|
Some(next_due) => match next_due <= Delta::now_time() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue