Commit c5eb4727 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Add method to set the todos creation date.

parent ada47bc3
......@@ -179,6 +179,21 @@ class TodoBase(object):
self.src = re.sub(r'^(\([A-Z]\) )?', \
'x ' + today.isoformat() + ' ', self.src)
def set_creation_date(self, date):
"""
Sets the creation date of a todo. Should be passed a date object.
"""
self.fields['creationDate'] = date
# not particulary pretty, but inspired by
# http://bugs.python.org/issue1519638 non-existent matches trigger
# exceptions, hence the lambda
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)), \
self.src)
def creation_date(self):
""" Returns the creation date of a todo. """
return self.fields['creationDate']
......
......@@ -228,5 +228,50 @@ class TodoBaseTester(unittest.TestCase):
self.assertEquals(todo.src, new_text)
self.assertEquals(todo.priority(),'C')
def test_set_creation_date1(self):
todo = TodoBase.TodoBase("Foo")
date = datetime.date(2014, 7, 24)
todo.set_creation_date(date)
self.assertEquals(todo.creation_date(), 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)
todo.set_creation_date(date)
self.assertEquals(todo.creation_date(), 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)
todo.set_creation_date(date)
self.assertEquals(todo.creation_date(), 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)
todo.set_creation_date(date)
self.assertEquals(todo.creation_date(), 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)
todo.set_creation_date(date)
self.assertEquals(todo.creation_date(), date)
self.assertEquals(todo.src, "x 2014-07-25 2014-07-24 Foo")
if __name__ == '__main__':
unittest.main()
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