]> granicus.if.org Git - python/commitdiff
Merge 3.4 (datetime rounding)
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 18 Sep 2015 12:50:18 +0000 (14:50 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 18 Sep 2015 12:50:18 +0000 (14:50 +0200)
1  2 
Lib/datetime.py
Lib/test/datetimetester.py
Misc/NEWS
Modules/_datetimemodule.c

diff --cc Lib/datetime.py
index db13b12ef3d0c4251429e3864d94c8f1f2d3a73f,3af12e7716dc637db54d749163f3522ca1285c15..b9719cbb48df0cadb665263a01e71739a20dcac0
@@@ -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."
Simple merge
diff --cc Misc/NEWS
index 191052946a2fe5c40dbe7d3126ab2da0de85c17a,d570bd49dc6fcc9f9855f9ba403ba990d6d47d40..9df2fc7a8763af6968d03816e22129474b00c6a2
+++ b/Misc/NEWS
@@@ -14,15 -13,82 +14,23 @@@ Core and Builtin
  Library
  -------
  
 -  towards zero (ROUND_DOWN). It's important that these methods use the same
 -  rounding mode than datetime.timedelta to keep the property:
+ - 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 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
Simple merge