Commit 05dbbf38 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Optionally ignore weekends when calculating importance.

No tests though, not sure how to properly test this. Monkey patching the
datetime module doesn't appear to be working on Linux.
parent f42a082e
......@@ -14,3 +14,4 @@ TAG_DUE = 'due'
TAG_STAR = 'star'
SORT_STRING = 'desc:importance,due,desc:priority'
IGNORE_WEEKENDS = True # for calculating the importance value
......@@ -7,14 +7,29 @@ today may have a higher importance than high priority tasks in the distant
future.
"""
import datetime
import Config
IMPORTANCE_VALUE = {'A': 3, 'B': 2, 'C': 1}
def importance(p_todo):
def is_due_next_monday(p_todo):
""" Returns True when the given task is due next Monday. """
today = datetime.date.today()
due = p_todo.due_date()
return due and due.weekday() == 0 and today.weekday() >= 4 and \
p_todo.days_till_due()
def importance(p_todo, p_ignore_weekend=False):
"""
Calculates the importance of the given task.
Returns an importance of zero when the task has been completed.
If p_ignore_weekend is True, the importance value of the due date will be
calculated as if Friday is immediately followed by Monday. This in case of
a todo list at the office and you don't work during the weekends (you
don't, right?)
"""
result = 2
......@@ -35,6 +50,9 @@ def importance(p_todo):
elif days_left < 0:
result += 6
if p_ignore_weekend and is_due_next_monday(p_todo):
result += 1
if p_todo.has_tag(Config.TAG_STAR):
result += 1
......
......@@ -3,6 +3,7 @@
import datetime
import re
import Config
from Importance import importance
def is_priority_field(p_field):
......@@ -28,7 +29,7 @@ def get_field_function(p_field):
result = (lambda a: a.completion_date() if a.completion_date() \
else datetime.date.max)
elif p_field == 'importance':
result = importance
result = lambda a: importance(a, Config.IGNORE_WEEKENDS)
elif p_field == 'text':
result = lambda a: a.text()
else:
......
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