From 77854f62ba8b9bdf57b81bf1c65b658d883eb163 Mon Sep 17 00:00:00 2001 From: Rhyd Lewis Date: Sun, 8 Mar 2020 08:36:30 +0000 Subject: [PATCH] Some defensive coding around date parse requests --- factory.py | 44 ++++++++++++++++++++++++++++---------------- info.plist | 2 +- version | 2 +- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/factory.py b/factory.py index 8235e0b..eda41ed 100644 --- a/factory.py +++ b/factory.py @@ -12,6 +12,7 @@ STATUS_DROPPED = 'dropped' STATUS_INACTIVE = 'inactive' DATETIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%fZ' +DATETIME_OFFSET = 978307200 FOLDER_PREFIX = 'en.lproj/OmniFocus Help/art/' @@ -96,20 +97,23 @@ def create_task(self, row): icon = self.deferred_icon if inbox: icon = self.inbox_icon - - if row[DUE_DATE]: - due_date = offset_date(row[DUE_DATE]) - now = datetime.now() - due_date_label = due_date.strftime("%c") - if now > due_date: - name = name + " (overdue: {0})".format(due_date_label) - icon = ICON_WARNING + if row[DUE_DATE]: + due_date = parse_datetime(row[DUE_DATE]) + if due_date is not None: + now = datetime.now() + due_date_label = due_date.strftime("%c") + + if now > due_date: + name = name + " (overdue: {0})".format(due_date_label) + icon = ICON_WARNING + else: + name = name + " (due: {0})".format(due_date_label) else: - name = name + " (due: {0})".format(due_date_label) + name = name + " (due date unknown)" return Item(item_type='Task', persistent_id=pid, name=name, icon=icon, subtitle=project) - + def create_context(self, raw_data): pid = raw_data[ID] name = raw_data[NAME] @@ -149,8 +153,14 @@ def create_recent_item(self, raw_data): else: task.name = task.name + " (Task)" - modified_date = offset_date(raw_data[MODIFIED_DATE]).strftime("%c") - task.subtitle = modified_date + mod_date = raw_data[MODIFIED_DATE] + + try: + modified_date = datetime.fromtimestamp(mod_date + DATETIME_OFFSET).strftime("%c") + task.subtitle = modified_date + except: + task.subtitle = "Unable to determine a modified date for this task {0}".format(mod_date) + return task @@ -162,12 +172,14 @@ def deferred_date(datetostart, effectivedatetostart): def is_deferred(datetostart): deferred = False if datetostart is not None: - dts = offset_date(datetostart) + dts = parse_datetime(datetostart) if dts > datetime.now(): deferred = True return deferred - -def offset_date(value): - return datetime.strptime(value, DATETIME_FORMAT) +def parse_datetime(value): + try: + return datetime.strptime(value, DATETIME_FORMAT) + except: + return None diff --git a/info.plist b/info.plist index a472c7b..a2d6df5 100644 --- a/info.plist +++ b/info.plist @@ -2233,7 +2233,7 @@ Well, I want it because I can't quickly search for, say, a task within OmniFocus variablesdontexport version - 2.1.0 + 2.1.1 webaddress rhydlewis.net diff --git a/version b/version index 7ec1d6d..3e3c2f1 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.1.0 +2.1.1