Commits

Andrew Wooster committed ef994b7

Fixing a bug in datetime handling in which datetime objects weren't round-tripping.

  • Participants
  • Parent commits 77a8e50

Comments (0)

Files changed (2)

biplist/__init__.py

 
 from collections import namedtuple
 from cStringIO import StringIO
+import calendar
 import datetime
 import math
 import plistlib
             output += pack('!B', (0b0010 << 4) | 3)
             output += self.binaryReal(obj)
         elif isinstance(obj, datetime.datetime):
-            timestamp = time.mktime(obj.timetuple())
+            timestamp = calendar.timegm(obj.utctimetuple())
             timestamp -= apple_reference_date_offset
             output += pack('!B', 0b00110011)
             output += pack('!d', float(timestamp))

tests/test_write.py

     def testSetRoot(self):
         self.roundTrip(set((1, 2, 3)))
     
+    def testDatetime(self):
+        now = datetime.datetime.utcnow()
+        now = now.replace(microsecond=0)
+        self.roundTrip([now])
+    
     def testFloat(self):
         self.roundTrip({'aFloat':1.23})