[Zope3-checkins] CVS: Zope3/src/datetime - _datetime.py:1.14

Tim Peters tim.one@comcast.net
Thu, 2 Jan 2003 11:19:10 -0500


Update of /cvs-repository/Zope3/src/datetime
In directory cvs.zope.org:/tmp/cvs-serv7522/src/datetime

Modified Files:
	_datetime.py 
Log Message:
SF bug 661086: datetime.today() truncates microseconds.
On Windows, it was very common to get microsecond values (out of
.today() and .now()) of the form 480999, i.e. with three trailing
nines.  The platform precision is .001 seconds, and fp rounding
errors account for the rest.  Under the covers, that 480999 started
life as the fractional part of a timestamp, like .4809999978.
Rounding that times 1e6 cures the irritation.


=== Zope3/src/datetime/_datetime.py 1.13 => 1.14 ===
--- Zope3/src/datetime/_datetime.py:1.13	Wed Jan  1 22:08:05 2003
+++ Zope3/src/datetime/_datetime.py	Thu Jan  2 11:19:07 2003
@@ -1275,7 +1275,7 @@
     def fromtimestamp(cls, t):
         "Construct a datetime from a POSIX timestamp (like time.time())."
         y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)
-        us = int((t % 1.0) * 1000000)
+        us = int(round((t % 1.0) * 1000000))
         return cls(y, m, d, hh, mm, ss, us)
     fromtimestamp = classmethod(fromtimestamp)