Commit d543bed3 authored by Bram Schoenmakers's avatar Bram Schoenmakers

Make the tag command convert relative dates

When the due date tag or the start date tag is set, convert the value to
an absolute date if a relative date was given.
parent 54db080a
......@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from freezegun import freeze_time
import unittest
from test.command_testcase import CommandTest
......@@ -138,6 +139,29 @@ class TagCommandTest(CommandTest):
"| 4| Fnord due:2014-10-20 due:2014-10-20\n")
self.assertEqual(self.errors, "")
@freeze_time('2015, 11, 19')
def test_set_tag11(self):
command = TagCommand(["3", "due", "today"], self.todolist, self.out,
self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEqual(self.output, "| 3| Baz due:2015-11-19\n")
self.assertEqual(self.errors, "")
def test_set_tag12(self):
"""
Do not convert relative dates for tags that were not configured as
start/due date.
"""
command = TagCommand(["3", "foo", "today"], self.todolist, self.out,
self.error)
command.execute()
self.assertTrue(self.todolist.is_dirty())
self.assertEqual(self.output, "| 3| Baz due:2014-10-20 foo:today\n")
self.assertEqual(self.errors, "")
def test_rm_tag01(self):
command = TagCommand(["1", "due"], self.todolist, self.out, self.error)
command.execute()
......
......@@ -15,7 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from topydo.lib.Command import Command, InvalidCommandArgument
from topydo.lib.Config import config
from topydo.lib.prettyprinters.Numbers import PrettyPrinterNumbers
from topydo.lib.RelativeDate import relative_date_to_date
from topydo.lib.TodoListBase import InvalidTodoException
......@@ -90,7 +92,16 @@ class TagCommand(Command):
return answer
def _convert_relative_dates(self):
if self.tag == config().tag_start() or self.tag == config().tag_due():
real_date = relative_date_to_date(self.value)
if real_date:
self.value = real_date.isoformat()
def _set_helper(self, p_old_value=""):
self._convert_relative_dates()
old_src = self.todo.source()
self.todo.set_tag(self.tag, self.value, self.force_add, p_old_value)
......
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