Commit 9d90c59f authored by Bram Schoenmakers's avatar Bram Schoenmakers

Let date_string_to_date raise ValueError instead of returning None.

parent d9efdf83
......@@ -41,7 +41,10 @@ class DoCommand(DCommand):
if p_opt == "-s" or p_opt == "--strict":
self.strict_recurrence = True
elif p_opt == "-d" or p_opt == "--date":
self.completion_date = date_string_to_date(p_value) or date.today()
try:
self.completion_date = date_string_to_date(p_value)
except ValueError:
self.completion_date = date.today()
def _handle_recurrence(self):
if self.todo.has_tag('rec'):
......
......@@ -175,8 +175,6 @@ class OrdinalTagFilter(Filter):
if not operand2:
operand2 = date_string_to_date(self.value)
if not operand1 or not operand2:
raise ValueError
except ValueError:
try:
operand1 = int(p_todo.tag_value(self.key))
......
......@@ -37,7 +37,14 @@ class Todo(TodoBase):
def get_date(self, p_tag):
""" Given a date tag, return a date object. """
string = self.tag_value(p_tag)
return date_string_to_date(string) if string else None
result = None
try:
result = date_string_to_date(string) if string else None
except ValueError:
pass
return result
def start_date(self):
""" Returns a date object of the todo's start date. """
......
......@@ -31,14 +31,13 @@ def date_string_to_date(p_date):
if p_date:
parsed_date = re.match(r'(\d{4})-(\d{2})-(\d{2})', p_date)
if parsed_date:
try:
result = date(
int(parsed_date.group(1)), # year
int(parsed_date.group(2)), # month
int(parsed_date.group(3)) # day
)
except ValueError:
result = None
result = date(
int(parsed_date.group(1)), # year
int(parsed_date.group(2)), # month
int(parsed_date.group(3)) # day
)
else:
raise ValueError
return result
......
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