[Zodb-checkins] SVN: ZODB/branches/tseaver-python_picklecache-2/src/persistent/timestamp.py Fix microsecond handling.
Tres Seaver
tseaver at palladion.com
Wed Feb 16 21:32:15 EST 2011
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'.
More information about the Zodb-checkins
mailing list