diff --git a/taskchampion/taskchampion/src/task/task.rs b/taskchampion/taskchampion/src/task/task.rs index ce0194fe6..1d2b7eb0d 100644 --- a/taskchampion/taskchampion/src/task/task.rs +++ b/taskchampion/taskchampion/src/task/task.rs @@ -379,9 +379,18 @@ impl<'r> TaskMut<'r> { } /// Set a tasks's property by name. + /// + /// This will not automatically update the `modified` timestamp or perform any other + /// "automatic" operations -- it simply sets the property. Howerver, if property is + /// "modified", then subsequent calls to other `set_..` methods will not update the + /// `modified` timestamp. pub fn set_value>(&mut self, property: S, value: Option) -> Result<()> { let property = property.into(); + if &property == "modified" { + self.updated_modified = true; + } + if let Some(ref v) = value { trace!("task {}: set property {}={:?}", self.task.uuid, property, v); } else { @@ -531,7 +540,7 @@ impl<'r> TaskMut<'r> { fn set_string>(&mut self, property: S, value: Option) -> Result<()> { let property = property.into(); - // updated the modified timestamp unless we are setting it explicitly + // update the modified timestamp unless we are setting it explicitly if &property != "modified" { self.update_modified()?; } @@ -1195,4 +1204,17 @@ mod test { assert!(t2.has_tag(&stag(SyntheticTag::Unblocked))); assert!(t2.has_tag(&stag(SyntheticTag::Blocking))); } + + #[test] + fn set_value_modiifed() { + with_mut_task(|mut task| { + // set the modified property to something in the past.. + task.set_value("modified", Some("1671820000".into())) + .unwrap(); + // update another property + task.set_description("fun times".into()).unwrap(); + // verify the modified property was not updated + assert_eq!(task.get_value("modified").unwrap(), "1671820000") + }) + } }