From 2b8918dd7cffc584077cf886ba7a70cbaa1ad6cd Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 25 Aug 2014 22:37:46 +0200 Subject: [PATCH] Return proper date type. --- scanner/PhotoAlbum.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py index aeb3087..fffe4ac 100644 --- a/scanner/PhotoAlbum.py +++ b/scanner/PhotoAlbum.py @@ -306,14 +306,19 @@ class Photo(object): return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes] @property def date(self): + correct_date = None; if not self.is_valid: - return datetime(1900, 1, 1) + correct_date = datetime(1900, 1, 1) if "dateTimeOriginal" in self._attributes: - return self._attributes["dateTimeOriginal"] + correct_date = self._attributes["dateTimeOriginal"] elif "dateTime" in self._attributes: - return self._attributes["dateTime"] + correct_date = self._attributes["dateTime"] else: - return self._attributes["dateTimeFile"] + correct_date = self._attributes["dateTimeFile"] + if isinstance(correct_date, unicode): + correct_date = datetime.strptime(correct_date, '%Y:%m:%d %H:%M:%S') + return correct_date + def __cmp__(self, other): date_compare = cmp(self.date, other.date) if date_compare == 0: