From 9824ac1fd32acf8e8887ec864827f038c1e51e6d Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Thu, 6 Jan 2022 02:18:32 +0000 Subject: [PATCH] add 'entry' key to tasks when created --- docs/src/tasks.md | 1 + taskchampion/src/replica.rs | 10 +++++++++- taskchampion/src/task/task.rs | 5 +++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/src/tasks.md b/docs/src/tasks.md index eb6756e22..c2a1258ba 100644 --- a/docs/src/tasks.md +++ b/docs/src/tasks.md @@ -33,6 +33,7 @@ The following keys, and key formats, are defined: * `start` - the most recent time at which this task was started (a task with no `start` key is not active) * `tag_` - indicates this task has tag `` (value is an empty string) * `wait` - indicates the time before which this task should be hidden, as it is not actionable +* `entry` - the time at which the task was created * `annotation_` - value is an annotation created at the given time The following are not yet implemented: diff --git a/taskchampion/src/replica.rs b/taskchampion/src/replica.rs index 2b833a323..5a02a59d6 100644 --- a/taskchampion/src/replica.rs +++ b/taskchampion/src/replica.rs @@ -108,6 +108,7 @@ impl Replica { let mut task = Task::new(uuid, taskmap).into_mut(self); task.set_description(description)?; task.set_status(status)?; + task.set_entry(Utc::now())?; Ok(task.into_immut()) } @@ -228,7 +229,7 @@ mod tests { .. } = op { - if property == "modified" { + if property == "modified" || property == "entry" { if value.is_some() { value = Some("just-now".into()); } @@ -277,6 +278,13 @@ mod tests { value: Some("pending".into()), timestamp: now, }, + ReplicaOp::Update { + uuid: t.get_uuid(), + property: "entry".into(), + old_value: None, + value: Some("just-now".into()), + timestamp: now, + }, ReplicaOp::Update { uuid: t.get_uuid(), property: "modified".into(), diff --git a/taskchampion/src/task/task.rs b/taskchampion/src/task/task.rs index 40a85ba87..12832103a 100644 --- a/taskchampion/src/task/task.rs +++ b/taskchampion/src/task/task.rs @@ -57,6 +57,7 @@ enum Prop { Start, Status, Wait, + Entry, } #[allow(clippy::ptr_arg)] @@ -277,6 +278,10 @@ impl<'r> TaskMut<'r> { self.set_string(Prop::Description.as_ref(), Some(description)) } + pub(crate) fn set_entry(&mut self, entry: DateTime) -> anyhow::Result<()> { + self.set_timestamp(Prop::Entry.as_ref(), Some(entry)) + } + pub fn set_wait(&mut self, wait: Option>) -> anyhow::Result<()> { self.set_timestamp(Prop::Wait.as_ref(), wait) }