Author: Brian Kearns <bdkea...@gmail.com> Branch: py3k Changeset: r62043:275233336f3c Date: 2013-03-04 21:56 -0500 http://bitbucket.org/pypy/pypy/changeset/275233336f3c/
Log: port datetime optimizations in 91b8e2795113 and 043d831e8736 diff --git a/lib-python/3/datetime.py b/lib-python/3/datetime.py --- a/lib-python/3/datetime.py +++ b/lib-python/3/datetime.py @@ -22,6 +22,9 @@ def _cmp(x, y): return 0 if x == y else 1 if x > y else -1 +def _round(x): + return _math.floor(x + 0.5) if x >= 0.0 else _math.ceil(x - 0.5) + MINYEAR = 1 MAXYEAR = 9999 _MAXORDINAL = 3652059 # date.max.toordinal() @@ -379,7 +382,7 @@ if isinstance(microseconds, float): microseconds += usdouble - microseconds = round(microseconds, 0) + microseconds = float(_round(microseconds)) seconds, microseconds = divmod(microseconds, 1e6) assert microseconds == int(microseconds) assert seconds == int(seconds) @@ -399,7 +402,7 @@ assert abs(s) <= 3 * 24 * 3600 microseconds = float(microseconds) microseconds += usdouble - microseconds = round(microseconds, 0) + microseconds = float(_round(microseconds)) assert abs(s) <= 3 * 24 * 3600 assert abs(microseconds) < 3.1e6 @@ -1364,7 +1367,7 @@ converter = _time.localtime if tz is None else _time.gmtime t, frac = divmod(t, 1.0) - us = round(frac * 1e6) + 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, @@ -1384,7 +1387,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 = _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, _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit