diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2009-10-28 09:50:11 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@fluendo.com> | 2009-10-28 09:50:11 +0100 |
commit | 0104da13ef883e1e7476b5434fca96135ba5aaed (patch) | |
tree | 1764cfe4b7cfe349d3c3806379b92beb1190e340 | |
parent | e34793b91ab8744371da9d06c2a763eb7c04d75d (diff) | |
download | pyexiv2-0104da13ef883e1e7476b5434fca96135ba5aaed.tar.gz |
Pass IPTC Dates to exiv2 in the correct format (%Y-%m-%d).
-rw-r--r-- | src/pyexiv2/iptc.py | 8 | ||||
-rw-r--r-- | test/iptc.py | 8 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/pyexiv2/iptc.py b/src/pyexiv2/iptc.py index 46d543f..d5afb96 100644 --- a/src/pyexiv2/iptc.py +++ b/src/pyexiv2/iptc.py @@ -205,8 +205,12 @@ class IptcTag(MetadataTag, ListenerInterface): elif self.type == 'Date': if type(value) in (datetime.date, datetime.datetime): - # ISO 8601 date format - return value.strftime('%Y%m%d') + # ISO 8601 date format. + # According to the IPTC specification, the format for a string + # field representing a date is '%Y%m%d'. However, the string + # expected by exiv2's DateValue::read(string) should be + # formatted using pattern '%Y-%m-%d'. + return value.strftime('%Y-%m-%d') else: raise IptcValueError(value, self.type) diff --git a/test/iptc.py b/test/iptc.py index 4a8e4fe..06d01dd 100644 --- a/test/iptc.py +++ b/test/iptc.py @@ -129,13 +129,13 @@ class TestIptcTag(unittest.TestCase): # Valid values tag = IptcTagMock('Iptc.Envelope.DateSent', type) self.assertEqual(tag._convert_to_string(datetime.date(2009, 2, 4)), - '20090204') + '2009-02-04') self.assertEqual(tag._convert_to_string(datetime.datetime(1999, 10, 13)), - '19991013') + '1999-10-13') self.assertEqual(tag._convert_to_string(datetime.datetime(2009, 2, 4)), - '20090204') + '2009-02-04') self.assertEqual(tag._convert_to_string(datetime.datetime(2009, 2, 4, 10, 52, 37)), - '20090204') + '2009-02-04') # Invalid values self.failUnlessRaises(IptcValueError, tag._convert_to_string, 'invalid') |