Commit b178a216 authored by Lysander Trischler's avatar Lysander Trischler

Fix bugs in sport.py

* parse ISO date correctly
* strptime is datetime class method
parent 3b06cbef
......@@ -114,9 +114,9 @@ if __name__ == "__main__":
return datetime.date.today() - datetime.timedelta(days=2)
if date == "vorvorgestern":
return datetime.date.today() - datetime.timedelta(days=3)
for fmt in ("%d.?", "%d.%m.?", "%d.%m.%Y", "%m-%d", "%Y-m-%d"):
for fmt in ("%d.?", "%d.%m.?", "%d.%m.%Y", "%m-%d", "%Y-%m-%d"):
try:
return datetime.date.strptime(date, fmt)
return datetime.datetime.strptime(date, fmt).date()
except ValueError:
pass
raise ValueError("Cannot parse date '%s'" % date)
......@@ -124,7 +124,7 @@ if __name__ == "__main__":
def resolve_time(time):
for fmt in ("%H:%M:%S", "%H:%M", "%M"):
try:
return datetime.time.strptime(time, fmt)
return datetime.datetime.strptime(time, fmt).time()
except ValueError:
pass
raise ValueError("Cannot parse time '%s'" % time)
......
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