From 494b04fdfb6f4c13098133822e7664468260e3bc Mon Sep 17 00:00:00 2001 From: John Keith Hohm Date: Mon, 19 May 2025 13:25:39 -0400 Subject: [PATCH 1/5] Change `datetime.now` to half-even rounding for consistency with `datetime.fromtimestamp`. --- Modules/_datetimemodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 9bba0e3354b26b..1feb10ab3bcb0f 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -5539,7 +5539,7 @@ 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); From 6b53c73a74245e20a8f1d1978153244f078d6c74 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 19 May 2025 18:12:43 +0000 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst 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 00000000000000..0a2c3cf3369900 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst @@ -0,0 +1 @@ +Change :func:`datetime.now` to half-even rounding for consistency with :func:`datetime.fromtimestamp`. From 654fcc43a4d9032ce3585ccbead02615d6e819fc Mon Sep 17 00:00:00 2001 From: John Keith Hohm Date: Mon, 19 May 2025 14:25:29 -0400 Subject: [PATCH 3/5] Fix func references in NEWS blurb to qualify `datetime` module contents. --- .../next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 index 0a2c3cf3369900..03eb768eb223e9 100644 --- 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 @@ -1 +1,2 @@ -Change :func:`datetime.now` to half-even rounding for consistency with :func:`datetime.fromtimestamp`. +Change :func:`datetime.datetime.now` to half-even rounding for +consistency with :func:`datetime.datetime.fromtimestamp`. From 84c6755502a13efb377c291fdfe877a0feba502d Mon Sep 17 00:00:00 2001 From: John Keith Hohm Date: Mon, 19 May 2025 15:01:08 -0400 Subject: [PATCH 4/5] Add jhohm to ACKS and note as author of patch --- Misc/ACKS | 1 + .../next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Misc/ACKS b/Misc/ACKS index 610dcf9f4238de..5bdd6b5540174b 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 index 03eb768eb223e9..554a0c3bcb26bf 100644 --- 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 @@ -1,2 +1,3 @@ Change :func:`datetime.datetime.now` to half-even rounding for -consistency with :func:`datetime.datetime.fromtimestamp`. +consistency with :func:`datetime.datetime.fromtimestamp`. Patch by +John Keith Hohm. From 15a97fd400d6dac058d8f6fbbc6d256406108c6e Mon Sep 17 00:00:00 2001 From: John Keith Hohm Date: Mon, 19 May 2025 15:19:35 -0400 Subject: [PATCH 5/5] Conform to PEP 7 on changed line. Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Modules/_datetimemodule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 1feb10ab3bcb0f..abbb763e93cab2 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -5539,8 +5539,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_HALF_EVEN) < 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);