aboutsummaryrefslogtreecommitdiffstats
path: root/src/pyexiv2.py
diff options
context:
space:
mode:
authorOlivier Tilloy <olivier@tilloy.net>2009-02-05 20:15:39 +0100
committerOlivier Tilloy <olivier@tilloy.net>2009-02-05 20:15:39 +0100
commit0c92278b84b6ad672e7212e460155f49c9c7437a (patch)
tree31d4b03c2b3811448937ba25bb6ae5f301fcbffa /src/pyexiv2.py
parentc6501e454229132808853648b818499ea4888f58 (diff)
downloadpyexiv2-0c92278b84b6ad672e7212e460155f49c9c7437a.tar.gz
XMP Date to string conversion + unit tests.
Diffstat (limited to 'src/pyexiv2.py')
-rw-r--r--src/pyexiv2.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/pyexiv2.py b/src/pyexiv2.py
index 8bb398a..aecb99b 100644
--- a/src/pyexiv2.py
+++ b/src/pyexiv2.py
@@ -141,8 +141,10 @@ class FixedOffset(datetime.tzinfo):
Keyword arguments:
dt -- the datetime.time object representing the local time
"""
- r = '%s%02d:%02d' % (self.sign, self.hours, self.minutes)
- return r
+ if self.hours == 0 and self.minutes == 0:
+ return 'Z'
+ else:
+ return '%s%02d:%02d' % (self.sign, self.hours, self.minutes)
def __equal__(self, other):
return (self.sign == other.sign) and (self.hours == other.hours) and \
@@ -660,6 +662,26 @@ class XmpTag(MetadataTag):
if xtype == 'Boolean' and type(value) is bool:
return str(value)
+ elif xtype == 'Date':
+ if type(value) is datetime.date:
+ return value.isoformat()
+ elif type(value) is datetime.datetime:
+ if value.hour == 0 and value.minute == 0 and \
+ value.second == 0 and value.microsecond == 0 and \
+ (value.tzinfo is None or value.tzinfo == FixedOffset()):
+ return value.strftime('%Y-%m-%d')
+ elif value.second == 0 and value.microsecond == 0:
+ return value.strftime('%Y-%m-%dT%H:%M%Z')
+ elif value.microsecond == 0:
+ return value.strftime('%Y-%m-%dT%H:%M:%S%Z')
+ else:
+ r = value.strftime('%Y-%m-%dT%H:%M:%S.')
+ r += str(int(value.microsecond) / 1E6)[2:]
+ r += value.strftime('%Z')
+ return r
+ else:
+ raise XmpValueError(value, xtype)
+
elif xtype == 'Integer':
if type(value) in (int, long):
return str(value)