Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug in datetime lib causes incorrect timedelta value #128765

Closed
oldwizard1010 opened this issue Jan 12, 2025 · 3 comments
Closed

Bug in datetime lib causes incorrect timedelta value #128765

oldwizard1010 opened this issue Jan 12, 2025 · 3 comments
Labels
extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir

Comments

@oldwizard1010
Copy link

oldwizard1010 commented Jan 12, 2025

Bug report

Bug description:

Problem with datetime lib

# Add a code block here, if required
import time
from datetime import datetime

x1 = (datetime.fromisoformat('2025-01-08T00:00:01') - datetime.utcnow()).seconds
time.sleep(5)
x2 = (datetime.fromisoformat('2025-01-08T00:00:01') - datetime.utcnow()).seconds
print(f"x1 should be less than x2, but x1={x1}, x2={x2}; x1<x2={x1<x2}")

CPython versions tested on:

3.12

Operating systems tested on:

Linux

@oldwizard1010 oldwizard1010 added the type-bug An unexpected behavior, bug, or error label Jan 12, 2025
@picnixz picnixz added the stdlib Python modules in the Lib dir label Jan 12, 2025
@picnixz picnixz added the extension-modules C modules in the Modules dir label Jan 12, 2025
@picnixz
Copy link
Member

picnixz commented Jan 12, 2025

For me, it works as expected. Precision is a bit lost but it's still correct (the delta is 5 seconds, so it's a <= and not an exact <):

image

If you want to check < you should also consider the microseconds part.

@picnixz picnixz added pending The issue will be closed if no feedback is provided and removed type-bug An unexpected behavior, bug, or error labels Jan 12, 2025
@vadmium
Copy link
Member

vadmium commented Jan 12, 2025

What was the “incorrect” value? Maybe this was done as seconds wrapped between zero and a whole day? Try using total_seconds.

@ericvsmith ericvsmith removed the pending The issue will be closed if no feedback is provided label Jan 24, 2025
@ericvsmith
Copy link
Member

Closing since there's no follow-up.

@ericvsmith ericvsmith closed this as not planned Won't fix, can't repro, duplicate, stale Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extension-modules C modules in the Modules dir stdlib Python modules in the Lib dir
Projects
Development

No branches or pull requests

4 participants