From 265e1259e4ad7001ea366d52c56adde8daed7a69 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 2 Sep 2015 01:57:23 +0200 Subject: [PATCH] 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. --- Misc/NEWS | 5 +++++ Modules/_datetimemodule.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Misc/NEWS b/Misc/NEWS index 38f31e4880..8226f20f27 100644 --- 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. diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 5cff3f8ffc..e1cd2b57a1 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -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); -- 2.40.0