From d79143ade7fab1ce8a07c9a8a09cf9a58a4f8b08 Mon Sep 17 00:00:00 2001 From: Olivier Tilloy Date: Sun, 16 Sep 2007 18:48:36 +0200 Subject: When setting a datetime or time tag value, truncate the unused information (microseconds). --- src/pyexiv2.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/pyexiv2.py') 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; -- cgit