[pypy-commit] pypy default: datetime.utcfromtimestamp() used to store microseconds as floats.

amauryfa noreply at buildbot.pypy.org
Fri Feb 10 01:22:05 CET 2012


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: 
Changeset: r52341:8a9843bb99ad
Date: 2012-02-10 01:19 +0100
http://bitbucket.org/pypy/pypy/changeset/8a9843bb99ad/

Log:	datetime.utcfromtimestamp() used to store microseconds as floats.

diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py
--- a/lib_pypy/datetime.py
+++ b/lib_pypy/datetime.py
@@ -1520,7 +1520,7 @@
     def utcfromtimestamp(cls, t):
         "Construct a UTC datetime from a POSIX timestamp (like time.time())."
         t, frac = divmod(t, 1.0)
-        us = round(frac * 1e6)
+        us = int(round(frac * 1e6))
 
         # If timestamp is less than one microsecond smaller than a
         # full second, us can be rounded up to 1000000.  In this case,
@@ -2125,3 +2125,7 @@
 pretty bizarre, and a tzinfo subclass can override fromutc() if it is.
 """
 
+if not hasattr(_time, '__datetime__dict'):
+    _time.__datetime__dict = globals()
+else:
+    globals().update(_time.__datetime__dict)
diff --git a/pypy/module/test_lib_pypy/test_datetime.py b/pypy/module/test_lib_pypy/test_datetime.py
--- a/pypy/module/test_lib_pypy/test_datetime.py
+++ b/pypy/module/test_lib_pypy/test_datetime.py
@@ -22,3 +22,7 @@
             del os.environ["TZ"]
         else:
             os.environ["TZ"] = prev_tz
+
+def test_utcfromtimestamp_microsecond():
+    dt = datetime.datetime.utcfromtimestamp(0)
+    assert isinstance(dt.microsecond, int)


More information about the pypy-commit mailing list