home
·
contact
·
privacy
projects
/
plomtask
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add date validation for Days.
[plomtask]
/
plomtask
/
days.py
diff --git
a/plomtask/days.py
b/plomtask/days.py
index 071b0b1b27d76b676d02ee4d4530563a5ba547b5..4e0c4747809bc1e352e492cf619fafb41f3f0bbb 100644
(file)
--- a/
plomtask/days.py
+++ b/
plomtask/days.py
@@
-1,15
+1,27
@@
"""Collecting Day and date-related items."""
from datetime import datetime
"""Collecting Day and date-related items."""
from datetime import datetime
+from plomtask.misc import HandledException
DATE_FORMAT = '%Y-%m-%d'
DATE_FORMAT = '%Y-%m-%d'
+def date_valid(date: str):
+ """Validate date against DATE_FORMAT, return Datetime or None."""
+ try:
+ result = datetime.strptime(date, DATE_FORMAT)
+ except (ValueError, TypeError):
+ return None
+ return result
+
+
class Day:
"""Individual days defined by their dates."""
def __init__(self, date: str):
self.date = date
class Day:
"""Individual days defined by their dates."""
def __init__(self, date: str):
self.date = date
- self.datetime = datetime.strptime(date, DATE_FORMAT)
+ self.datetime = date_valid(self.date)
+ if not self.datetime:
+ raise HandledException(f'Given date of wrong format: {self.date}')
@property
def weekday(self):
@property
def weekday(self):