]> granicus.if.org Git - python/commitdiff
Issue #23517: datetime.datetime.fromtimestamp() and
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 1 Sep 2015 23:57:23 +0000 (01:57 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 1 Sep 2015 23:57:23 +0000 (01:57 +0200)
datetime.datetime.utcfromtimestamp() now rounds to nearest with ties going away
from zero, instead of rounding towards minus infinity (-inf), as Python 2 and
Python older than 3.3.

Misc/NEWS
Modules/_datetimemodule.c

index 38f31e4880476af81876e5bb1370495da96a556a..8226f20f27f578bef23ed58ce5ae8762485dc4d8 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,11 @@ Core and Builtins
 Library
 -------
 
+- Issue #23517: datetime.datetime.fromtimestamp() and
+  datetime.datetime.utcfromtimestamp() now rounds to nearest with ties going
+  away from zero, instead of rounding towards minus infinity (-inf), as Python
+  2 and Python older than 3.3.
+
 - Issue #23552: Timeit now warns when there is substantial (4x) variance
   between best and worst times. Patch from Serhiy Storchaka.
 
index 5cff3f8ffc1a853682635cb17d5a3b315de5aec5..e1cd2b57a1a50aedeb847da4f575c6c7e3333e44 100644 (file)
@@ -4098,7 +4098,7 @@ datetime_from_timestamp(PyObject *cls, TM_FUNC f, PyObject *timestamp,
     long us;
 
     if (_PyTime_ObjectToTimeval(timestamp,
-                                &timet, &us, _PyTime_ROUND_FLOOR) == -1)
+                                &timet, &us, _PyTime_ROUND_HALF_UP) == -1)
         return NULL;
 
     return datetime_from_timet_and_us(cls, f, timet, (int)us, tzinfo);