Commit 589cb4fa authored by Bram Schoenmakers's avatar Bram Schoenmakers

Allow negative time periods to be specified.

This can be used for ordinal tag filters, for instance for getting the
todo items with a date older than 6 months:

topydo ls 'due:<-6m'
parent b9a346ac
......@@ -62,10 +62,6 @@ class RelativeDateTester(TopydoTest.TopydoTest):
result = relative_date_to_date('0dd')
self.assertFalse(result)
def test_garbage2(self):
result = relative_date_to_date('-0d')
self.assertFalse(result)
def test_one_day_capital(self):
result = relative_date_to_date('1D')
self.assertEquals(result, self.tomorrow)
......@@ -111,5 +107,13 @@ class RelativeDateTester(TopydoTest.TopydoTest):
result = relative_date_to_date('1d', self.tomorrow)
self.assertEquals(result, date.today() + timedelta(2))
def test_negative_period1(self):
result = relative_date_to_date('-1d')
self.assertEquals(result, date.today() - timedelta(1))
def test_negative_period2(self):
result = relative_date_to_date('-0d')
self.assertTrue(result, self.today)
if __name__ == '__main__':
unittest.main()
......@@ -80,7 +80,7 @@ def relative_date_to_date(p_date, p_offset=date.today()):
result = None
p_date = p_date.lower()
relative = re.match('(?P<length>[0-9]+)(?P<period>[dwmy])$', p_date, re.I)
relative = re.match('(?P<length>-?[0-9]+)(?P<period>[dwmy])$', p_date, re.I)
monday = 'mo(n(day)?)?$'
tuesday = 'tu(e(sday)?)?$'
......
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