From: John Keith Hohm Date: Mon, 19 May 2025 20:48:55 +0000 (-0400) Subject: gh-88994: Change `datetime.datetime.now` to half-even rounding (#134258) X-Git-Tag: v3.15.0a1~1650 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=470941782f74288823b445120f6383914b659f23;p=thirdparty%2FPython%2Fcpython.git gh-88994: Change `datetime.datetime.now` to half-even rounding (#134258) Change `datetime.datetime.now` to half-even rounding for consistency with `datetime.fromtimestamp`. --- diff --git a/Misc/ACKS b/Misc/ACKS index 5653c52c9e35..1b500870dec4 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -795,6 +795,7 @@ Albert Hofkamp Chris Hogan Tomas Hoger Jonathan Hogg +John Keith Hohm Vladyslav Hoi Kamilla Holanda Steve Holden diff --git a/Misc/NEWS.d/next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst b/Misc/NEWS.d/next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst new file mode 100644 index 000000000000..554a0c3bcb26 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst @@ -0,0 +1,3 @@ +Change :func:`datetime.datetime.now` to half-even rounding for +consistency with :func:`datetime.datetime.fromtimestamp`. Patch by +John Keith Hohm. diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 313a72e3fe06..eb90be81c8d3 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -5551,8 +5551,9 @@ datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo) time_t secs; int us; - if (_PyTime_AsTimevalTime_t(ts, &secs, &us, _PyTime_ROUND_FLOOR) < 0) + if (_PyTime_AsTimevalTime_t(ts, &secs, &us, _PyTime_ROUND_HALF_EVEN) < 0) { return NULL; + } assert(0 <= us && us <= 999999); return datetime_from_timet_and_us(cls, f, secs, us, tzinfo);