mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-23 05:27:47 +02:00
Implement due dates related methods for Task and TaskMut (#3145)
* Implement due dates related methods for Task and TaskMut * Merge add_due and remove_due into the single method called set_due * reformat the file
This commit is contained in:
parent
c86252d693
commit
76b21f49e8
1 changed files with 57 additions and 0 deletions
|
@ -64,6 +64,7 @@ pub struct TaskMut<'r> {
|
|||
#[strum(serialize_all = "kebab-case")]
|
||||
enum Prop {
|
||||
Description,
|
||||
Due,
|
||||
Modified,
|
||||
Start,
|
||||
Status,
|
||||
|
@ -277,6 +278,11 @@ impl Task {
|
|||
self.get_timestamp(Prop::Modified.as_ref())
|
||||
}
|
||||
|
||||
/// Get the due time for this task.
|
||||
pub fn get_due(&self) -> Option<Timestamp> {
|
||||
self.get_timestamp(Prop::Due.as_ref())
|
||||
}
|
||||
|
||||
/// Get the UUIDs of tasks on which this task depends.
|
||||
///
|
||||
/// This includes all dependencies, regardless of their status. In fact, it may include
|
||||
|
@ -458,6 +464,10 @@ impl<'r> TaskMut<'r> {
|
|||
self.set_string(format!("annotation_{}", entry.timestamp()), None)
|
||||
}
|
||||
|
||||
pub fn set_due(&mut self, due: Option<Timestamp>) -> Result<()> {
|
||||
self.set_timestamp(Prop::Due.as_ref(), due)
|
||||
}
|
||||
|
||||
/// Set a user-defined attribute (UDA). This will fail if the key is defined by the data
|
||||
/// model.
|
||||
pub fn set_uda(
|
||||
|
@ -745,6 +755,53 @@ mod test {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_due() {
|
||||
let test_time = Utc.ymd(2033, 1, 1).and_hms(0, 0, 0);
|
||||
let task = Task::new(
|
||||
Uuid::new_v4(),
|
||||
vec![(String::from("due"), format!("{}", test_time.timestamp()))]
|
||||
.drain(..)
|
||||
.collect(),
|
||||
dm(),
|
||||
);
|
||||
assert_eq!(task.get_due(), Some(test_time))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_invalid_due() {
|
||||
let task = Task::new(
|
||||
Uuid::new_v4(),
|
||||
vec![(String::from("due"), String::from("invalid"))]
|
||||
.drain(..)
|
||||
.collect(),
|
||||
dm(),
|
||||
);
|
||||
assert_eq!(task.get_due(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add_due() {
|
||||
let test_time = Utc.ymd(2033, 1, 1).and_hms(0, 0, 0);
|
||||
with_mut_task(|mut task| {
|
||||
assert_eq!(task.get_due(), None);
|
||||
task.set_due(Some(test_time)).unwrap();
|
||||
assert_eq!(task.get_due(), Some(test_time))
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_remove_due() {
|
||||
let test_time = Utc.ymd(2033, 1, 1).and_hms(0, 0, 0);
|
||||
with_mut_task(|mut task| {
|
||||
task.set_due(Some(test_time)).unwrap();
|
||||
task.reload().unwrap();
|
||||
assert!(task.taskmap.contains_key("due"));
|
||||
task.set_due(None).unwrap();
|
||||
assert!(!task.taskmap.contains_key("due"));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_priority_default() {
|
||||
let task = Task::new(Uuid::new_v4(), TaskMap::new(), dm());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue