Commit 3da4d82b authored by Bram Schoenmakers's avatar Bram Schoenmakers

Guard for missing dates.

parent d5ff3de3
...@@ -20,7 +20,7 @@ class Todo(TodoBase.TodoBase): ...@@ -20,7 +20,7 @@ class Todo(TodoBase.TodoBase):
def get_date(self, p_tag): def get_date(self, p_tag):
""" Given a date tag, return a date object. """ """ Given a date tag, return a date object. """
string = self.tag_value(p_tag) string = self.tag_value(p_tag)
return Utils.date_string_to_date(string) return Utils.date_string_to_date(string) if string else None
def start_date(self): def start_date(self):
""" Returns a date object of the todo's start date. """ """ Returns a date object of the todo's start date. """
......
...@@ -12,18 +12,18 @@ def date_string_to_date(p_date): ...@@ -12,18 +12,18 @@ def date_string_to_date(p_date):
""" """
result = None result = None
parsed_date = re.match(r'(\d{4})-(\d{2})-(\d{2})', p_date) if p_date:
parsed_date = re.match(r'(\d{4})-(\d{2})-(\d{2})', p_date)
if parsed_date:
try:
date = datetime.date(
int(parsed_date.group(1)), # year
int(parsed_date.group(2)), # month
int(parsed_date.group(3)) # day
)
if parsed_date: result = date
try: except ValueError:
date = datetime.date( pass # just return None
int(parsed_date.group(1)), # year
int(parsed_date.group(2)), # month
int(parsed_date.group(3)) # day
)
result = date
except ValueError:
pass # just return None
return result 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