Commit 92f372cb authored by Bram Schoenmakers's avatar Bram Schoenmakers

Import date from datetime, instead of mentioning datetime everywhere.

parent f1d2414d
......@@ -7,7 +7,7 @@ today may have a higher importance than high priority tasks in the distant
future.
"""
import datetime
from datetime import date
import Config
......@@ -15,7 +15,7 @@ IMPORTANCE_VALUE = {'A': 3, 'B': 2, 'C': 1}
def is_due_next_monday(p_todo):
""" Returns True when the given task is due next Monday. """
today = datetime.date.today()
today = date.today()
due = p_todo.due_date()
return due and due.weekday() == 0 and today.weekday() >= 4 and \
......
#!/usr/bin/env python
""" Entry file for the Python todo.txt CLI. """
import datetime
from datetime import date
import re
import sys
......@@ -76,7 +76,7 @@ def postprocess_input_todo(p_todo):
if date:
p_todo.set_tag(tag, date.isoformat())
p_todo.set_creation_date(datetime.date.today())
p_todo.set_creation_date(date.today())
class Application(object):
def __init__(self):
......
""" This module provides functionality to sort lists with todo items. """
import datetime
from datetime import date
import re
import Config
......@@ -24,10 +24,10 @@ def get_field_function(p_field):
# when a task has no creation date, push it to the end by assigning it
# the maximum possible date.
result = (lambda a: a.creation_date() if a.creation_date() \
else datetime.date.max)
else date.max)
elif p_field == 'done' or p_field == 'completed' or p_field == 'completion':
result = (lambda a: a.completion_date() if a.completion_date() \
else datetime.date.max)
else date.max)
elif p_field == 'importance':
result = lambda a: importance(a, Config.IGNORE_WEEKENDS)
elif p_field == 'importance-avg' or p_field == 'importance-average':
......
......@@ -2,7 +2,7 @@
This module provides the Todo class.
"""
import datetime
from datetime import date
import Config
import Utils
......@@ -37,8 +37,7 @@ class Todo(TodoBase.TodoBase):
task has not yet been completed.
"""
start = self.start_date()
return not self.is_completed() and \
(not start or start <= datetime.date.today())
return not self.is_completed() and (not start or start <= date.today())
def is_overdue(self):
"""
......@@ -55,7 +54,7 @@ class Todo(TodoBase.TodoBase):
"""
due = self.due_date()
if due:
diff = due - datetime.date.today()
diff = due - date.today()
return diff.days
return 0
......
......@@ -2,7 +2,7 @@
This module contains the class that represents a single todo item.
"""
import datetime
from datetime import date
import re
import TodoParser
......@@ -172,17 +172,17 @@ class TodoBase(object):
self.set_priority(None)
self.fields['completed'] = True
today = datetime.date.today()
today = date.today()
self.fields['completionDate'] = today
self.src = re.sub(r'^(\([A-Z]\) )?', \
'x ' + today.isoformat() + ' ', self.src)
def set_creation_date(self, date=datetime.date.today()):
def set_creation_date(self, p_date=date.today()):
"""
Sets the creation date of a todo. Should be passed a date object.
"""
self.fields['creationDate'] = date
self.fields['creationDate'] = p_date
# not particulary pretty, but inspired by
# http://bugs.python.org/issue1519638 non-existent matches trigger
......@@ -190,7 +190,7 @@ class TodoBase(object):
self.src = re.sub(
r'^(x \d{4}-\d{2}-\d{2} |\([A-Z]\) )?(\d{4}-\d{2}-\d{2} )?(.*)$', \
lambda m: \
"%s%s %s" % (m.group(1) or '', date.isoformat(), m.group(3)), \
"%s%s %s" % (m.group(1) or '', p_date.isoformat(), m.group(3)), \
self.src)
def creation_date(self):
......
......@@ -2,7 +2,7 @@
Various utility functions.
"""
import datetime
from datetime import date
import re
def date_string_to_date(p_date):
......@@ -16,14 +16,12 @@ def date_string_to_date(p_date):
parsed_date = re.match(r'(\d{4})-(\d{2})-(\d{2})', p_date)
if parsed_date:
try:
date = datetime.date(
result = date(
int(parsed_date.group(1)), # year
int(parsed_date.group(2)), # month
int(parsed_date.group(3)) # day
)
result = date
except ValueError:
pass # just return None
result = None
return result
""" Tests for the filter functionality. """
import datetime
import unittest
import Filter
......
import datetime
from datetime import date
import unittest
import Config
......@@ -19,6 +19,6 @@ class ImportanceTest(unittest.TestCase):
self.assertEqual(importance(todo), 6)
def test_importance4(self):
today_str = datetime.date.today().isoformat()
today_str = date.today().isoformat()
todo = Todo.Todo("(C) Foo " + Config.TAG_DUE + ":" + today_str)
self.assertEqual(importance(todo), 8)
""" Tests for the TodoBase class. """
import datetime
from datetime import date
import re
import unittest
......@@ -191,7 +191,7 @@ class TodoBaseTester(unittest.TestCase):
todo = TodoBase.TodoBase("(A) Foo")
todo.set_completed()
today = datetime.date.today()
today = date.today()
today_str = today.isoformat()
self.assertFalse(todo.priority())
......@@ -202,7 +202,7 @@ class TodoBaseTester(unittest.TestCase):
todo = TodoBase.TodoBase("2014-06-12 Foo")
todo.set_completed()
today = datetime.date.today()
today = date.today()
today_str = today.isoformat()
self.assertEquals(todo.fields['completionDate'], today)
......@@ -213,7 +213,7 @@ class TodoBaseTester(unittest.TestCase):
todo = TodoBase.TodoBase("Foo")
todo.set_completed()
today = datetime.date.today()
today = date.today()
today_str = today.isoformat()
self.assertEquals(todo.fields['completionDate'], today)
......@@ -223,7 +223,7 @@ class TodoBaseTester(unittest.TestCase):
todo = TodoBase.TodoBase("(A) 2014-06-12 Foo")
todo.set_completed()
today = datetime.date.today()
today = date.today()
today_str = today.isoformat()
self.assertEquals(todo.fields['completionDate'], today)
......@@ -246,47 +246,47 @@ class TodoBaseTester(unittest.TestCase):
def test_set_creation_date1(self):
todo = TodoBase.TodoBase("Foo")
date = datetime.date(2014, 7, 24)
creation_date = date(2014, 7, 24)
todo.set_creation_date(date)
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "2014-07-24 Foo")
def test_set_creation_date2(self):
todo = TodoBase.TodoBase("(A) Foo")
date = datetime.date(2014, 7, 24)
creation_date = date(2014, 7, 24)
todo.set_creation_date(date)
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "(A) 2014-07-24 Foo")
def test_set_creation_date3(self):
todo = TodoBase.TodoBase("(A) 2014-07-23 Foo")
date = datetime.date(2014, 7, 24)
creation_date = date(2014, 7, 24)
todo.set_creation_date(date)
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "(A) 2014-07-24 Foo")
def test_set_creation_date4(self):
todo = TodoBase.TodoBase("2014-07-23 Foo")
date = datetime.date(2014, 7, 24)
creation_date = date(2014, 7, 24)
todo.set_creation_date(date)
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "2014-07-24 Foo")
def test_set_creation_date5(self):
todo = TodoBase.TodoBase("x 2014-07-25 2014-07-23 Foo")
date = datetime.date(2014, 7, 24)
creation_date = date(2014, 7, 24)
todo.set_creation_date(date)
todo.set_creation_date(creation_date)
self.assertEquals(todo.creation_date(), date)
self.assertEquals(todo.creation_date(), creation_date)
self.assertEquals(todo.src, "x 2014-07-25 2014-07-24 Foo")
if __name__ == '__main__':
......
""" Tests for the TodoList class. """
import datetime
import re
import unittest
......
import datetime
from datetime import date, timedelta
import unittest
import Todo
def today_date():
date = datetime.date.today()
return date.isoformat()
today = date.today()
return today.isoformat()
def tomorrow_date():
date = datetime.date.today() + datetime.timedelta(days=1)
return date.isoformat()
tomorrow = date.today() + timedelta(days=1)
return tomorrow.isoformat()
class TodoTest(unittest.TestCase):
def test_due_date1(self):
todo = Todo.Todo("(C) Foo due:2014-06-09")
date = datetime.date(2014, 6, 9)
due = date(2014, 6, 9)
self.assertEqual(todo.due_date(), date)
self.assertEqual(todo.due_date(), due)
def test_false_date(self):
todo = Todo.Todo("(C) Foo due:2014-04-31")
......
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