You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
datetime.timedelta is inconvenient to use... #50038
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:
assignee=Noneclosed_at=<Date2009-11-25.23:04:49.969>created_at=<Date2009-04-18.18:37:39.661>labels= ['type-feature', 'library']
title='datetime.timedelta is inconvenient to use...'updated_at=<Date2011-10-21.20:34:13.603>user='https://github.com/brianquinlan'
I did add a patch description: "Adds a datetime.total_seconds attribute"
is that unclear?
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
description, and perhaps a motivation as well, in the comment. That way
it's easier for people to directly see what an issue is about.
datetime.timedelta instances are a convenient way of representing
durations
datetime.timedelta instances cannot be conveniently used in many
calculations e.g. calculating distance based on velocity and time
datetime.timedelta instances cannot be conveniently used in many
library functions e.g. time.sleep(), urllib2.urlopen(timeout=)
I propose to fix that by adding a timedelta.total_seconds attribute that
equals:
timedelta.days * 3600 * 24 + timedelta.seconds + timedelta.microseconds
/ 100000.0
The addition looks quite legitimate to me.
The only thing is that it may be better as a method (total_seconds())
rather than an attribute, given the other APIs in the datetime module.
Also, the patch lacks some unit tests.
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.
Would it be a reasonable addition?
If so I'll open a separate issue.
Activity
brianquinlan commentedon Apr 18, 2009
...in seconds-based library functions (e.g. time.sleep) and calculations
(e.g. distance = velocity * ?).
birkenfeld commentedon Apr 18, 2009
Please include a proper description of your problem, and a patch
description when you post a patch.
brianquinlan commentedon Apr 18, 2009
I did add a patch description: "Adds a datetime.total_seconds attribute"
birkenfeld commentedon Apr 18, 2009
I saw the patch description as well, but usually you put that
description, and perhaps a motivation as well, in the comment. That way
it's easier for people to directly see what an issue is about.
brianquinlan commentedon Apr 18, 2009
OK, a bit on motivation:
durations
calculations e.g. calculating distance based on velocity and time
library functions e.g. time.sleep(), urllib2.urlopen(timeout=)
I propose to fix that by adding a timedelta.total_seconds attribute that
equals:
timedelta.days * 3600 * 24 + timedelta.seconds + timedelta.microseconds
/ 100000.0
pitrou commentedon Apr 18, 2009
The addition looks quite legitimate to me.
The only thing is that it may be better as a method (total_seconds())
rather than an attribute, given the other APIs in the datetime module.
Also, the patch lacks some unit tests.
pitrou commentedon Apr 18, 2009
Sorry for the last comment about unit tests, they are here actually :-)
brianquinlan commentedon Apr 19, 2009
Attached is a patch that implements .total_seconds as an instance method
pitrou commentedon May 14, 2009
Given the timing, I fear this will have to wait for 3.2.
pitrou commentedon Nov 25, 2009
The patch is committed in r76529 (trunk) and r76530 (py3k). Thank you!
mdickinson commentedon Nov 26, 2009
A late note: this would be redundant if the oft-requested division of
timedeltas were implemented: t.total_seconds could then be spelt
t/timedelta(seconds=1)
with the advantage that there would then be a natural way to spell
t.total_days or t.total_hours as well.
mdickinson commentedon Nov 26, 2009
That should be t.total_seconds(), of course.
pitrou commentedon Nov 26, 2009
It would be less obvious, though.
giampaolo commentedon Oct 19, 2011
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.
Would it be a reasonable addition?
If so I'll open a separate issue.
mdickinson commentedon Oct 21, 2011
What about
?
brianquinlan commentedon Oct 21, 2011
You'll probably get more traction if you file a new bug.