Skip to content

Commit 4709417

Browse files
authored
gh-88994: Change datetime.datetime.now to half-even rounding (#134258)
Change `datetime.datetime.now` to half-even rounding for consistency with `datetime.fromtimestamp`.
1 parent 42d03f3 commit 4709417

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ Albert Hofkamp
795795
Chris Hogan
796796
Tomas Hoger
797797
Jonathan Hogg
798+
John Keith Hohm
798799
Vladyslav Hoi
799800
Kamilla Holanda
800801
Steve Holden
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Change :func:`datetime.datetime.now` to half-even rounding for
2+
consistency with :func:`datetime.datetime.fromtimestamp`. Patch by
3+
John Keith Hohm.

Modules/_datetimemodule.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5551,8 +5551,9 @@ datetime_best_possible(PyObject *cls, TM_FUNC f, PyObject *tzinfo)
55515551
time_t secs;
55525552
int us;
55535553

5554-
if (_PyTime_AsTimevalTime_t(ts, &secs, &us, _PyTime_ROUND_FLOOR) < 0)
5554+
if (_PyTime_AsTimevalTime_t(ts, &secs, &us, _PyTime_ROUND_HALF_EVEN) < 0) {
55555555
return NULL;
5556+
}
55565557
assert(0 <= us && us <= 999999);
55575558

55585559
return datetime_from_timet_and_us(cls, f, secs, us, tzinfo);

0 commit comments

Comments
 (0)