From: Victor Stinner Date: Fri, 18 Sep 2015 12:50:18 +0000 (+0200) Subject: Merge 3.4 (datetime rounding) X-Git-Tag: v3.5.1rc1~331 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84ff4abd795d2cbe9f732bfd28bdc2316ab0f0bc;p=python Merge 3.4 (datetime rounding) --- 84ff4abd795d2cbe9f732bfd28bdc2316ab0f0bc diff --cc Lib/datetime.py index db13b12ef3,3af12e7716..b9719cbb48 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@@ -1395,20 -1397,13 +1401,8 @@@ class datetime(date) @classmethod def utcfromtimestamp(cls, t): """Construct a naive UTC datetime from a POSIX timestamp.""" - t, frac = divmod(t, 1.0) - us = int(frac * 1e6) - - # If timestamp is less than one microsecond smaller than a - # full second, us can be rounded up to 1000000. In this case, - # roll over to seconds, otherwise, ValueError is raised - # by the constructor. - if us == 1000000: - t += 1 - us = 0 - y, m, d, hh, mm, ss, weekday, jday, dst = _time.gmtime(t) - ss = min(ss, 59) # clamp out leap seconds if the platform has them - return cls(y, m, d, hh, mm, ss, us) + return cls._fromtimestamp(t, True, None) - # XXX This is supposed to do better than we *can* do by using time.time(), - # XXX if the platform supports a more accurate way. The C implementation - # XXX uses gettimeofday on platforms that have it, but that isn't - # XXX available from Python. So now() may return different results - # XXX across the implementations. @classmethod def now(cls, tz=None): "Construct a datetime from time.time() and optional time zone info." diff --cc Misc/NEWS index 191052946a,d570bd49dc..9df2fc7a87 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -14,15 -13,82 +14,23 @@@ Core and Builtin Library ------- + - Issue #23517: Fix rounding in fromtimestamp() and utcfromtimestamp() methods + of datetime.datetime: microseconds are now rounded to nearest with ties + going to nearest even integer (ROUND_HALF_EVEN), instead of being rounding - towards zero (ROUND_DOWN). It's important that these methods use the same - rounding mode than datetime.timedelta to keep the property: ++ towards minus infinity (ROUND_FLOOR). It's important that these methods use ++ the same rounding mode than datetime.timedelta to keep the property: + (datetime(1970,1,1) + timedelta(seconds=t)) == datetime.utcfromtimestamp(t). + It also the rounding mode used by round(float) for example. + +- Issue #25155: Fix datetime.datetime.now() and datetime.datetime.utcnow() on + Windows to support date after year 2038. It was a regression introduced in + Python 3.5.0. + +- Issue #25108: Omitted internal frames in traceback functions print_stack(), + format_stack(), and extract_stack() called without arguments. + +- Issue #25118: Fix a regression of Python 3.5.0 in os.waitpid() on Windows. + - Issue #24684: socket.socket.getaddrinfo() now calls PyUnicode_AsEncodedString() instead of calling the encode() method of the host, to handle correctly custom string with an encode() method which doesn't