[pypy-commit] pypy default: Issue #2048
arigo
noreply at buildbot.pypy.org
Fri May 15 08:00:43 CEST 2015
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r77326:795f867b8407
Date: 2015-05-15 08:00 +0200
http://bitbucket.org/pypy/pypy/changeset/795f867b8407/
Log: Issue #2048
Don't call "divmod(t, 1.0)". This is just a compatibility trick
with the C version of the datetime module in CPython, which doesn't
call t.__divmod__() even if it is defined on the class of t.
diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py
--- a/lib_pypy/datetime.py
+++ b/lib_pypy/datetime.py
@@ -1507,8 +1507,13 @@
converter = _time.localtime if tz is None else _time.gmtime
- t, frac = divmod(t, 1.0)
- us = _round(frac * 1e6)
+ if isinstance(t, int):
+ us = 0
+ else:
+ t_full = t
+ t = int(_math.floor(t))
+ frac = t_full - t
+ us = _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,
@@ -1527,8 +1532,13 @@
@classmethod
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)
+ if isinstance(t, int):
+ us = 0
+ else:
+ t_full = t
+ t = int(_math.floor(t))
+ frac = t_full - t
+ us = _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,
More information about the pypy-commit
mailing list