SVN: ZODB/branches/tseaver-python_picklecache-2/src/persistent/timestamp.py Fix microsecond handling.

Tres Seaver <[email protected]> Wed, 16 Feb 2011 21:32:15 -0500 (EST)
Newsgroups gmane.comp.python.zope.zodb.cvs
Message-ID <20110217023215.BA763941C4__47972.2874159508$1297909944$gmane$org@cvs.zope.org>
Log message for revision 120402:
  Fix microsecond handling.

Changed:
  U   ZODB/branches/tseaver-python_picklecache-2/src/persistent/timestamp.py

-=-
Modified: ZODB/branches/tseaver-python_picklecache-2/src/persistent/timestamp.py
===================================================================
--- ZODB/branches/tseaver-python_picklecache-2/src/persistent/timestamp.py	2011-02-17 02:32:13 UTC (rev 120401)
+++ ZODB/branches/tseaver-python_picklecache-2/src/persistent/timestamp.py	2011-02-17 02:32:15 UTC (rev 120402)
@@ -14,6 +14,7 @@
 __all__ = ('TimeStamp',)
 
 import datetime
+import math
 import struct
 import sys
 
@@ -44,7 +45,10 @@
         return dt
 
 def _makeUTC(y, mo, d, h, mi, s):
-    return datetime.datetime(y, mo, d, h, mi, s, tzinfo=_UTC())
+    usec, sec = math.modf(s)
+    sec = int(sec)
+    usec = int(usec * 1e6)
+    return datetime.datetime(y, mo, d, h, mi, sec, usec, tzinfo=_UTC())
 
 _EPOCH = _makeUTC(1970, 1, 1, 0, 0, 0)
 
@@ -111,7 +115,7 @@
         """ -> seconds since epoch, as a float.
         """
         delta = _makeUTC(*self._elements) - _EPOCH
-        return delta.days * 86400 + delta.seconds
+        return delta.days * 86400.0 + delta.seconds
 
     def laterThan(self, other):
         """ Return a timestamp instance which is later than 'other'.