Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-88994: Changedatetime.now
to half-even rounding for consistency withdatetime.fromtimestamp
.#134258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…etime.fromtimestamp`.
python-cla-botbot commentedMay 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Most changes to Pythonrequire a NEWS entry. Add one using theblurb_it web app or theblurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Would you mind to sign the CLA? |
You should add a NEWS entry to document your change, seehttps://devguide.python.org/ which explains how to add one. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@@ -0,0 +1,2 @@ | |||
Change :func:`datetime.datetime.now` to half-even rounding for | |||
consistency with :func:`datetime.datetime.fromtimestamp`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
If you want you can also add "Patch by (Your name however you want it rendered)." here.
StanFromIreland commentedMay 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I am unable to reproduce such success on Linux? |
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
4709417
intopython:mainUh oh!
There was an error while loading.Please reload this page.
Merged, thank you for your contribution! |
StanFromIreland commentedMay 19, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@vstinner out of curiosity does it work for you, it's hard to believe it's somehow windows only. |
Using a debug build, I failed to reproduce the issue. I trust the code, I know what it does :-) |
Huh; I can still reproduce the problem but only on a release Linux build. I'm investigating to see if there's something else I can do to ensure consistency there. |
time.time() uses float which is not great in terms of accuracy. Using time.time_ns() would be better. Sadly, there is no "fromtimestampns()" function. |
Uh oh!
There was an error while loading.Please reload this page.
Resolves#88994 where, on platforms with nanosecond resolution system clocks (such as Windows), the truncation within
datetime.now
could cause time to appear to go backwards by 1 microsecond betweendatetime.datetime.fromtimestamp(time.time(), None)
anddatetime.datetime.now()
.As suggested by@pganssle, not adding a test that would probably be flaky since it would involve comparing the results of multiple reads of the system clock. Verified manually that the following quickly fails the assert on Windows but passes with this commit: