Skip to content

Commit

Permalink
fix issue where recurring tasks are marked as todo but put into the i…
Browse files Browse the repository at this point in the history
…nactive subdir
  • Loading branch information
ardunn committed Aug 28, 2020
1 parent 6bf9a2a commit 9e7b6fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
18 changes: 10 additions & 8 deletions dex/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,16 @@ def set_status(self, new_status: str) -> bool:
if new_status == self.status:
return False

# For incomplete recurring tasks, keep the due date as it was previously (will go negative)
# For recurring tasks being set to "done", move the due date to the current due date + recurrence time
is_recurring, days_recurring = self.recurrence

if new_status == done_str and is_recurring:
# The status for a recurring task will remain undone
self.due = self.due + datetime.timedelta(days=days_recurring)
new_status = todo_str


active_statuses = [ip_str, todo_str, hold_str]
inactive_statuses = [abandoned_str, done_str]
if (new_status in inactive_statuses and self.status in active_statuses) or \
Expand All @@ -198,14 +208,6 @@ def set_status(self, new_status: str) -> bool:
self.prefix_path = new_prefix_path
self.path = new_path

# For incomplete recurring tasks, keep the due date as it was previously (will go negative)
# For recurring tasks being set to "done", move the due date to the current due date + recurrence time
is_recurring, days_recurring = self.recurrence

if new_status == done_str and is_recurring:
# The status for a recurring task will remain undone
self.due = self.due + datetime.timedelta(days=days_recurring)
new_status = todo_str

self.status = new_status
self._write_state()
Expand Down
8 changes: 6 additions & 2 deletions dex/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def test_set_status(self):
t = Task.from_file(test_file)
self.assertEqual(t.status, todo_str)


def test_setters(self):
test_file = os.path.join(self.test_dir, 'example task.md')
t = Task.from_file(test_file)
Expand Down Expand Up @@ -207,9 +208,12 @@ def test_recurrence(self):
# completed recurring task should be set to todo, not done as it will never recur!
self.assertEqual(t_recurring.status, todo_str)

t_recurring = Task.from_file(os.path.join(self.test_dir, f"{inactive_subdir}/recurring task.md"))
self.assertEqual(t_recurring.due, datetime.datetime.strptime("2020-07-30", due_date_fmt))
# Changing a recurring task from todo to done (i.e., updating the due)
t_recurring.set_status(done_str)
self.assertEqual(t_recurring.status, todo_str)
print(t_recurring.due)
self.assertEqual(t_recurring.due, datetime.datetime.strptime("2020-08-04", due_date_fmt))
self.assertEqual(t_recurring.path, test_file_recurring)


# Tests dependent on more than 1 method
Expand Down

0 comments on commit 9e7b6fa

Please sign in to comment.