diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2007-09-16 18:48:36 +0200 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2007-09-16 18:48:36 +0200 |
commit | d79143ade7fab1ce8a07c9a8a09cf9a58a4f8b08 (patch) | |
tree | 42f7cc52904f8d0b4c583a2426b6c1ee27de5ca8 /src/pyexiv2.py | |
parent | bee06f46ec991819ee25d86f5cee70209e4f8279 (diff) | |
download | pyexiv2-d79143ade7fab1ce8a07c9a8a09cf9a58a4f8b08.tar.gz |
When setting a datetime or time tag value, truncate the unused information (microseconds).
Diffstat (limited to 'src/pyexiv2.py')
-rw-r--r-- | src/pyexiv2.py | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py index 9254d03..a23bfd9 100644 --- a/src/pyexiv2.py +++ b/src/pyexiv2.py @@ -519,6 +519,11 @@ class Image(libpyexiv2.Image): tagFamily = key[:4] if tagFamily == 'Exif': if value is not None: + # For datetime objects, microseconds are not supported by the + # EXIF specification, so truncate them if present. + if value.__class__ is datetime.datetime: + value = value.replace(microsecond=0) + self.__setExifTagValue(key, value) self.__exifTagsDict[key] = value else: @@ -549,6 +554,17 @@ class Image(libpyexiv2.Image): except KeyError: # The tag is not set yet oldValues = () + + # For time objects, microseconds are not supported by the IPTC + # specification, so truncate them if present. + tempNewValues = [] + for newValue in newValues: + if newValue.__class__ is datetime.time: + tempNewValues.append(newValue.replace(microsecond=0)) + else: + tempNewValues.append(newValue) + newValues = tuple(tempNewValues) + # This loop processes the values one by one. There are n cases: # * if the two tuples are of the exact same size, each item in # oldValues is replaced by its new value in newValues; |