Commit 274ddf0e authored by Bram Schoenmakers's avatar Bram Schoenmakers

A start date takes precedence over recurrence when calculating length

A weekly recurring task with the start date one day before the due date,
shouldn't be colored orange/yellow when the task starts, but green.

Moreover, items where start date == due_date should have a length of 1.
parent e033d799
......@@ -125,24 +125,24 @@ class ProgressColorTest(TopydoTest):
def test_progress17(self):
""" Due tomorrow (creation date + recurrence + start date) """
color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 rec:1d t:2016-01-02'))
self.assertEqual(color.color, 2)
self.assertEqual(color.color, 3)
def test_progress18(self):
""" Due tomorrow (creation date + recurrence + start date) """
set_256_colors()
color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 rec:1d t:2016-01-02'))
self.assertEqual(color.color, 22)
self.assertEqual(color.color, 208)
def test_progress19(self):
""" Due tomorrow (creation date + strict recurrence + start date) """
color = progress_color(Todo('2016-12-01 Foo due:2016-01-02 rec:+1d t:2016-01-02'))
self.assertEqual(color.color, 2)
self.assertEqual(color.color, 3)
def test_progress20(self):
""" Due tomorrow (creation date + strict recurrence + start date) """
set_256_colors()
color = progress_color(Todo('2015-12-01 Foo due:2016-01-02 rec:+1d t:2016-01-02'))
self.assertEqual(color.color, 22)
self.assertEqual(color.color, 208)
def test_progress21(self):
""" Due tomorrow (creation date + start date) """
......
......@@ -48,7 +48,9 @@ def progress_color(p_todo):
diff = p_end - p_start
return diff.days
if p_todo.has_tag('rec') and p_todo.due_date():
if p_todo.has_tag('rec') and p_todo.due_date() \
and not p_todo.start_date():
# add negation, offset is based on due date
recurrence_pattern = p_todo.tag_value('rec')
neg_recurrence_pattern = re.sub('^\+?', '-', recurrence_pattern)
......@@ -61,7 +63,8 @@ def progress_color(p_todo):
else:
result = p_todo.length()
return result
# a todo item is at least one day long
return max(1, result)
def get_progress():
"""
......@@ -73,7 +76,7 @@ def progress_color(p_todo):
return 1.1
elif p_todo.due_date():
days_till_due = p_todo.days_till_due()
length = get_length() or 14
length = get_length()
return max((length - days_till_due), 0) / length
else:
return 0
......
......@@ -94,5 +94,7 @@ class Todo(TodoBase):
if start and due and start < due:
diff = due - start
return diff.days
elif start and due and start == due:
return 1
else:
return 0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment