Return proper date type.

master
Jason A. Donenfeld 2014-08-25 22:37:46 +02:00
parent ba69da0fde
commit 2b8918dd7c
1 changed files with 9 additions and 4 deletions

View File

@ -306,14 +306,19 @@ class Photo(object):
return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes] return [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes]
@property @property
def date(self): def date(self):
correct_date = None;
if not self.is_valid: if not self.is_valid:
return datetime(1900, 1, 1) correct_date = datetime(1900, 1, 1)
if "dateTimeOriginal" in self._attributes: if "dateTimeOriginal" in self._attributes:
return self._attributes["dateTimeOriginal"] correct_date = self._attributes["dateTimeOriginal"]
elif "dateTime" in self._attributes: elif "dateTime" in self._attributes:
return self._attributes["dateTime"] correct_date = self._attributes["dateTime"]
else: 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): def __cmp__(self, other):
date_compare = cmp(self.date, other.date) date_compare = cmp(self.date, other.date)
if date_compare == 0: if date_compare == 0: