entry and wait time support

This commit is contained in:
Dustin J. Mitchell
2022-02-01 02:45:28 +00:00
parent f2b3e5fd0a
commit e5625e1597
8 changed files with 190 additions and 14 deletions

View File

@@ -120,6 +120,10 @@ impl Task {
.unwrap_or("")
}
pub fn get_entry(&self) -> Option<DateTime<Utc>> {
self.get_timestamp(Prop::Entry.as_ref())
}
pub fn get_priority(&self) -> Priority {
self.taskmap
.get(Prop::Status.as_ref())
@@ -299,8 +303,8 @@ impl<'r> TaskMut<'r> {
self.set_string(Prop::Description.as_ref(), Some(description))
}
pub(crate) fn set_entry(&mut self, entry: DateTime<Utc>) -> anyhow::Result<()> {
self.set_timestamp(Prop::Entry.as_ref(), Some(entry))
pub fn set_entry(&mut self, entry: Option<DateTime<Utc>>) -> anyhow::Result<()> {
self.set_timestamp(Prop::Entry.as_ref(), entry)
}
pub fn set_wait(&mut self, wait: Option<DateTime<Utc>>) -> anyhow::Result<()> {
@@ -526,6 +530,24 @@ mod test {
assert!(!task.is_active());
}
#[test]
fn test_entry_not_set() {
let task = Task::new(Uuid::new_v4(), TaskMap::new());
assert_eq!(task.get_entry(), None);
}
#[test]
fn test_entry_set() {
let ts = Utc.ymd(1980, 1, 1).and_hms(0, 0, 0);
let task = Task::new(
Uuid::new_v4(),
vec![(String::from("entry"), format!("{}", ts.timestamp()))]
.drain(..)
.collect(),
);
assert_eq!(task.get_entry(), Some(ts));
}
#[test]
fn test_wait_not_set() {
let task = Task::new(Uuid::new_v4(), TaskMap::new());