diff options
author | Olivier Tilloy <olivier@tilloy.net> | 2010-12-22 18:18:20 +0100 |
---|---|---|
committer | Olivier Tilloy <olivier@tilloy.net> | 2010-12-22 18:18:20 +0100 |
commit | 12fe3dd984c4526062c8fe426b05f1789dfe8b74 (patch) | |
tree | 3d5a52e1bf25ece253364c4544fbc7ee65d1691c | |
parent | cbf24e672c0111e2b3982188e5d88dc9fe8421b4 (diff) | |
parent | 59ee4d6f36aaaea03dc9ffcacaf338903392db06 (diff) | |
download | pyexiv2-12fe3dd984c4526062c8fe426b05f1789dfe8b74.tar.gz |
Merged the latest changes from the trunk.
-rw-r--r-- | src/pyexiv2/iptc.py | 13 | ||||
-rw-r--r-- | test/iptc.py | 20 |
2 files changed, 19 insertions, 14 deletions
diff --git a/src/pyexiv2/iptc.py b/src/pyexiv2/iptc.py index 1e5429e..128f77e 100644 --- a/src/pyexiv2/iptc.py +++ b/src/pyexiv2/iptc.py @@ -346,11 +346,16 @@ class IptcTag(ListenerInterface): elif self.type == 'Time': if isinstance(value, (datetime.time, datetime.datetime)): - r = value.strftime('%H%M%S') - if value.tzinfo is not None: - r += value.strftime('%z') + # According to the IPTC specification, the format for a string + # field representing a time is '%H%M%S±%H%M'. However, the + # string expected by exiv2's TimeValue::read(string) should be + # formatted using pattern '%H:%M:%S±%H:%M'. + r = value.strftime('%H:%M:%S') + if value.tzinfo is not None and \ + not (value.tzinfo.hours == 0 and value.tzinfo.minutes == 0): + r += value.strftime('%Z') else: - r += '+0000' + r += '+00:00' return r else: raise IptcValueError(value, self.type) diff --git a/test/iptc.py b/test/iptc.py index ead0f47..9cf198e 100644 --- a/test/iptc.py +++ b/test/iptc.py @@ -137,25 +137,25 @@ class TestIptcTag(unittest.TestCase): tag = IptcTag('Iptc.Envelope.TimeSent') self.assertEqual(tag.type, 'Time') self.assertEqual(tag._convert_to_string(datetime.time(10, 52, 4)), - '105204+0000') + '10:52:04+00:00') self.assertEqual(tag._convert_to_string(datetime.time(10, 52, 4, 574)), - '105204+0000') + '10:52:04+00:00') self.assertEqual(tag._convert_to_string(datetime.time(10, 52, 4, tzinfo=FixedOffset())), - '105204+0000') + '10:52:04+00:00') self.assertEqual(tag._convert_to_string(datetime.time(10, 52, 4, tzinfo=FixedOffset('+', 5, 30))), - '105204+0530') + '10:52:04+05:30') self.assertEqual(tag._convert_to_string(datetime.time(10, 52, 4, tzinfo=FixedOffset('-', 4, 0))), - '105204-0400') + '10:52:04-04:00') self.assertEqual(tag._convert_to_string(datetime.datetime(2007, 2, 7, 10, 52, 4)), - '105204+0000') + '10:52:04+00:00') self.assertEqual(tag._convert_to_string(datetime.datetime(2007, 2, 7, 10, 52, 4, 478)), - '105204+0000') + '10:52:04+00:00') self.assertEqual(tag._convert_to_string(datetime.datetime(2007, 2, 7, 10, 52, 4, tzinfo=FixedOffset())), - '105204+0000') + '10:52:04+00:00') self.assertEqual(tag._convert_to_string(datetime.datetime(2007, 2, 7, 10, 52, 4, tzinfo=FixedOffset('+', 5, 30))), - '105204+0530') + '10:52:04+05:30') self.assertEqual(tag._convert_to_string(datetime.datetime(2007, 2, 7, 10, 52, 4, tzinfo=FixedOffset('-', 4, 0))), - '105204-0400') + '10:52:04-04:00') # Invalid values self.failUnlessRaises(IptcValueError, tag._convert_to_string, 'invalid') |