Commit d9e26efd authored by Bram Schoenmakers's avatar Bram Schoenmakers

do -d now understands relative dates

To complete a todo item that you finished yesterday, run

    topydo do -d yesterday

Or

    topydo do -d -1d
parent d22c4bc7
...@@ -304,6 +304,32 @@ class DoCommandTest(CommandTest): ...@@ -304,6 +304,32 @@ class DoCommandTest(CommandTest):
self.assertEqual(self.output, "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {yesterday} Strict due:2014-01-01 rec:1d\n".format(today=self.today, yesterday=self.yesterday)) self.assertEqual(self.output, "| 12| {today} Strict due:2014-01-02 rec:1d\nCompleted: x {yesterday} Strict due:2014-01-01 rec:1d\n".format(today=self.today, yesterday=self.yesterday))
self.assertEqual(self.errors, "") self.assertEqual(self.errors, "")
def test_do_custom_date8(self):
"""
Convert relative completion dates to an absolute date (yesterday).
"""
command = DoCommand(["-d", "yesterday", "3"], self.todolist, self.out,
self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEqual(self.output,
"Completed: x {} Baz p:1\n".format(self.yesterday))
self.assertEqual(self.errors, "")
def test_do_custom_date9(self):
"""
Convert relative completion dates to an absolute date (-1d)
"""
command = DoCommand(["-d", "-1d", "3"], self.todolist, self.out,
self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEqual(self.output,
"Completed: x {} Baz p:1\n".format(self.yesterday))
self.assertEqual(self.errors, "")
def test_multi_do1(self): def test_multi_do1(self):
command = DoCommand(["1", "3"], self.todolist, self.out, self.error, command = DoCommand(["1", "3"], self.todolist, self.out, self.error,
_yes_prompt) _yes_prompt)
......
...@@ -20,6 +20,7 @@ from topydo.lib.DCommand import DCommand ...@@ -20,6 +20,7 @@ from topydo.lib.DCommand import DCommand
from topydo.lib.PrettyPrinter import PrettyPrinter from topydo.lib.PrettyPrinter import PrettyPrinter
from topydo.lib.prettyprinters.Numbers import PrettyPrinterNumbers from topydo.lib.prettyprinters.Numbers import PrettyPrinterNumbers
from topydo.lib.Recurrence import NoRecurrenceException, advance_recurring_todo from topydo.lib.Recurrence import NoRecurrenceException, advance_recurring_todo
from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.Utils import date_string_to_date from topydo.lib.Utils import date_string_to_date
...@@ -48,6 +49,9 @@ class DoCommand(DCommand): ...@@ -48,6 +49,9 @@ class DoCommand(DCommand):
self.strict_recurrence = True self.strict_recurrence = True
elif p_opt == "-d" or p_opt == "--date": elif p_opt == "-d" or p_opt == "--date":
try: try:
self.completion_date = relative_date_to_date(p_value)
if not self.completion_date:
self.completion_date = date_string_to_date(p_value) self.completion_date = date_string_to_date(p_value)
except ValueError: except ValueError:
self.completion_date = date.today() self.completion_date = date.today()
......
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