]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-88994: Change `datetime.datetime.now` to half-even rounding (#134258)
authorJohn Keith Hohm <john@hohm.net>
Mon, 19 May 2025 20:48:55 +0000 (16:48 -0400)
committerGitHub <noreply@github.com>
Mon, 19 May 2025 20:48:55 +0000 (22:48 +0200)
Change `datetime.datetime.now` to half-even rounding
for consistency with `datetime.fromtimestamp`.

Misc/ACKS
Misc/NEWS.d/next/Library/2025-05-19-18-12-42.gh-issue-88994.7avvVu.rst [new file with mode: 0644]
Modules/_datetimemodule.c

index 5653c52c9e354e872ba6d6f8223bd22278b89567..1b500870dec4726bf8b5bf165590715271674d49 100644 (file)
--- 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 (file)
index 0000000..554a0c3
--- /dev/null
@@ -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.
index 313a72e3fe06680e52a6a9ee7c43fed18621782d..eb90be81c8d34c20c89b7a361e01caac073d22a3 100644 (file)
@@ -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);