diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-08-04 20:34:45 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2009-08-04 20:34:45 +0200 |
commit | bedad87240fdc63dc37c1fd859642284eed63a74 (patch) | |
tree | 042cdc628bf2454eb84ce97387b8e9801435064e /src | |
parent | 9e0d90e6e337faceaa75bb61888785c3afe9f028 (diff) | |
download | pyexiv2-bedad87240fdc63dc37c1fd859642284eed63a74.tar.gz |
Correctly handle decoding/encoding Exif.GPSInfo.GPSDateStamp.
Diffstat (limited to 'src')
-rw-r--r-- | src/pyexiv2.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py index 4fa4e31..991421a 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -476,6 +476,8 @@ class ExifTag(MetadataTag): '%Y-%m-%d %H:%M:%S', '%Y-%m-%dT%H:%M:%SZ') + _date_formats = ('%Y:%m:%d',) + def __init__(self, key, name, label, description, type, value, fvalue): super(ExifTag, self).__init__(key, name, label, description, type, value) @@ -525,13 +527,21 @@ class ExifTag(MetadataTag): """ if self.type == 'Ascii': # The value may contain a Datetime - for format in ExifTag._datetime_formats: + for format in self._datetime_formats: try: t = time.strptime(value, format) except ValueError: continue else: return datetime.datetime(*t[:6]) + # Or a Date (e.g. Exif.GPSInfo.GPSDateStamp) + for format in self._date_formats: + try: + t = time.strptime(value, format) + except ValueError: + continue + else: + return datetime.date(*t[:3]) # Default to string try: return unicode(value, 'utf-8') @@ -586,9 +596,13 @@ class ExifTag(MetadataTag): """ if self.type == 'Ascii': if type(value) is datetime.datetime: - return value.strftime('%Y:%m:%d %H:%M:%S') + return value.strftime(self._datetime_formats[0]) elif type(value) is datetime.date: - return value.strftime('%Y:%m:%d 00:00:00') + if self.key == 'Exif.GPSInfo.GPSDateStamp': + # Special case + return value.strftime(self._date_formats[0]) + else: + return value.strftime('%s 00:00:00' % self._date_formats[0]) elif type(value) is unicode: try: return value.encode('utf-8') |