[pypy-svn] r76326 - in pypy/trunk/lib_pypy: . pypy_test

hruske at codespeak.net hruske at codespeak.net
Fri Jul 23 13:32:32 CEST 2010


Author: hruske
Date: Fri Jul 23 13:32:30 2010
New Revision: 76326

Modified:
   pypy/trunk/lib_pypy/datetime.py
   pypy/trunk/lib_pypy/pypy_test/test_datetime.py
Log:
Fix and test for issue 548 - timestamps were rounded differently in PyPy and CPython.


Modified: pypy/trunk/lib_pypy/datetime.py
==============================================================================
--- pypy/trunk/lib_pypy/datetime.py	(original)
+++ pypy/trunk/lib_pypy/datetime.py	Fri Jul 23 13:32:30 2010
@@ -1412,7 +1412,7 @@
 
     def utcfromtimestamp(cls, t):
         "Construct a UTC datetime from a POSIX timestamp (like time.time())."
-        if 1 - (t % 1.0) < 0.000001:
+        if 1 - (t % 1.0) < 0.0000005:
             t = float(int(t)) + 1
         if t < 0:
             t -= 1

Modified: pypy/trunk/lib_pypy/pypy_test/test_datetime.py
==============================================================================
--- pypy/trunk/lib_pypy/pypy_test/test_datetime.py	(original)
+++ pypy/trunk/lib_pypy/pypy_test/test_datetime.py	Fri Jul 23 13:32:30 2010
@@ -15,4 +15,18 @@
     expected = datetime.datetime(*(time.strptime(string, format)[0:6]))
     got = datetime.datetime.strptime(string, format)
     assert expected == got
+
+def test_datetime_rounding():
+    b = 0.0000001
+    a = 0.9999994
+
+    assert datetime.datetime.utcfromtimestamp(a).microsecond == 999999
+    assert datetime.datetime.utcfromtimestamp(a).second == 0
+    a += b
+    assert datetime.datetime.utcfromtimestamp(a).microsecond == 999999
+    assert datetime.datetime.utcfromtimestamp(a).second == 0
+    a += b
+    assert datetime.datetime.utcfromtimestamp(a).microsecond == 0
+    assert datetime.datetime.utcfromtimestamp(a).second == 1
+
     



More information about the Pypy-commit mailing list