From 8d2f9198c2b5aa3b2ee481718223b6b6f55db8c6 Mon Sep 17 00:00:00 2001 From: Jim Miller Date: Mon, 11 Nov 2019 14:38:30 -0600 Subject: [PATCH] Add some code to handle 24 hr clocks w/o changing adapters. --- fanficfare/adapters/base_adapter.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/fanficfare/adapters/base_adapter.py b/fanficfare/adapters/base_adapter.py index 74ad64b7..76ab366a 100644 --- a/fanficfare/adapters/base_adapter.py +++ b/fanficfare/adapters/base_adapter.py @@ -620,8 +620,19 @@ def makeDate(string,dateform): add_hours = True string = string.replace(u"AM",u"").replace(u"PM",u"").replace(u"am",u"").replace(u"pm",u"") - # date = datetime.strptime(string.encode('utf-8'),dateform.encode('utf-8')) - date = datetime.strptime(string, dateform) + dateform = dateform.strip() + string = string.strip() + try: + date = datetime.strptime(string, dateform) + except ValueError: + ## If parse fails and looking for 01-12 hours, try 01-24 hours too. + ## A moderately cheesy way to support 12 and 24 hour clocks. + if u"%I" in dateform: + dateform = dateform.replace(u"%I",u"%H") + date = datetime.strptime(string, dateform) + add_hours = False + else: + raise if add_hours: date += timedelta(hours=12)