gh-88994: Change datetime.datetime.now to half-even rounding (#134258)

Change `datetime.datetime.now` to half-even rounding
for consistency with `datetime.fromtimestamp`.
This commit is contained in:
John Keith Hohm 2025-05-19 16:48:55 -04:00 committed by GitHub
parent 42d03f3933
commit 470941782f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 1 deletions

View file

@ -795,6 +795,7 @@ Albert Hofkamp
Chris Hogan
Tomas Hoger
Jonathan Hogg
John Keith Hohm
Vladyslav Hoi
Kamilla Holanda
Steve Holden

View file

@ -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.

View 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);