From 1d095d7284bae57037b8b200c8b3422835c611b2 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Sat, 23 May 2020 17:40:57 -0700 Subject: [PATCH] Added try/except for bad datettime values --- osxphotos/_version.py | 2 +- osxphotos/photosdb/photosdb.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/osxphotos/_version.py b/osxphotos/_version.py index 82be511b..709950d9 100644 --- a/osxphotos/_version.py +++ b/osxphotos/_version.py @@ -1,3 +1,3 @@ """ version info """ -__version__ = "0.29.0" +__version__ = "0.29.2" diff --git a/osxphotos/photosdb/photosdb.py b/osxphotos/photosdb/photosdb.py index 67f62feb..0bd2316a 100644 --- a/osxphotos/photosdb/photosdb.py +++ b/osxphotos/photosdb/photosdb.py @@ -798,17 +798,19 @@ class PhotosDB: # There are sometimes negative values for lastmodifieddate in the database # I don't know what these mean but they will raise exception in datetime if # not accounted for - if row[4] is not None and row[4] >= 0: + try: self._dbphotos[uuid]["lastmodifieddate"] = datetime.fromtimestamp( row[4] + td ) - else: + except ValueError: + self._dbphotos[uuid]["lastmodifieddate"] = None + except TypeError: self._dbphotos[uuid]["lastmodifieddate"] = None try: self._dbphotos[uuid]["imageDate"] = datetime.fromtimestamp(row[5] + td) except ValueError: - self._dbphotos[uuid]["imageDate"] = datetime.date(1970,1,1) + self._dbphotos[uuid]["imageDate"] = datetime.date(1970, 1, 1) self._dbphotos[uuid]["mainRating"] = row[6] self._dbphotos[uuid]["hasAdjustments"] = row[7] @@ -1516,12 +1518,18 @@ class PhotosDB: # There are sometimes negative values for lastmodifieddate in the database # I don't know what these mean but they will raise exception in datetime if # not accounted for - if row[4] is not None and row[4] >= 0: + try: info["lastmodifieddate"] = datetime.fromtimestamp(row[4] + td) - else: + except ValueError: + info["lastmodifieddate"] = None + except TypeError: info["lastmodifieddate"] = None - info["imageDate"] = datetime.fromtimestamp(row[5] + td) + try: + info["imageDate"] = datetime.fromtimestamp(row[5] + td) + except ValueError: + info["imageDate"] = datetime.date(1970, 1, 1) + info["imageTimeZoneOffsetSeconds"] = row[6] info["hidden"] = row[9] info["favorite"] = row[10]