[Python-checkins] python/nondist/sandbox/datetime datetime.py,1.136,1.137

tim_one@users.sourceforge.net tim_one@users.sourceforge.net
Thu, 02 Jan 2003 08:16:30 -0800


Update of /cvsroot/python/python/nondist/sandbox/datetime
In directory sc8-pr-cvs1:/tmp/cvs-serv24973

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.


Index: datetime.py
===================================================================
RCS file: /cvsroot/python/python/nondist/sandbox/datetime/datetime.py,v
retrieving revision 1.136
retrieving revision 1.137
diff -C2 -d -r1.136 -r1.137
*** datetime.py	2 Jan 2003 12:58:58 -0000	1.136
--- datetime.py	2 Jan 2003 16:16:27 -0000	1.137
***************
*** 1283,1287 ****
          "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)
          return cls(y, m, d, hh, mm, ss, us)
      fromtimestamp = classmethod(fromtimestamp)
--- 1283,1287 ----
          "Construct a datetime from a POSIX timestamp (like time.time())."
          y, m, d, hh, mm, ss, weekday, jday, dst = _time.localtime(t)
!         us = int(round((t % 1.0) * 1000000))
          return cls(y, m, d, hh, mm, ss, us)
      fromtimestamp = classmethod(fromtimestamp)