-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
datetime.timedelta is inconvenient to use... #50038
Comments
...in seconds-based library functions (e.g. time.sleep) and calculations |
Please include a proper description of your problem, and a patch |
I did add a patch description: "Adds a datetime.total_seconds attribute"
The idea is that you should be able to extract the total number of
seconds in the duration i.e.
>>> dt = datetime.timedelta(seconds=1234567.89)
>>> dt.total_seconds
1234567.89 |
I saw the patch description as well, but usually you put that |
OK, a bit on motivation:
I propose to fix that by adding a timedelta.total_seconds attribute that |
The addition looks quite legitimate to me. |
Sorry for the last comment about unit tests, they are here actually :-) |
Attached is a patch that implements .total_seconds as an instance method |
Given the timing, I fear this will have to wait for 3.2. |
The patch is committed in r76529 (trunk) and r76530 (py3k). Thank you! |
A late note: this would be redundant if the oft-requested division of t/timedelta(seconds=1) with the advantage that there would then be a natural way to spell |
That should be t.total_seconds(), of course. |
It would be less obvious, though. |
Sorry for commenting on a closed issue but I just bumped into a problem requiring a total_minute() method I ended up implementing by doing some raw math by hand. |
What about def total_minutes(td):
return td / datetime.timedelta(minutes=1) ? |
You'll probably get more traction if you file a new bug. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: