This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2009年04月18日 18:37 by bquinlan, last changed 2022年04月11日 14:56 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| totalseconds.diff | bquinlan, 2009年04月18日 18:38 | Adds a datetime.total_seconds attribute | ||
| totalseconds2.diff | bquinlan, 2009年04月19日 12:06 | implement total_seconds as a method | ||
| Messages (16) | |||
|---|---|---|---|
| msg86132 - (view) | Author: Brian Quinlan (bquinlan) * (Python committer) | Date: 2009年04月18日 18:37 | |
...in seconds-based library functions (e.g. time.sleep) and calculations (e.g. distance = velocity * ?). |
|||
| msg86133 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2009年04月18日 19:22 | |
Please include a proper description of your problem, and a patch description when you post a patch. |
|||
| msg86135 - (view) | Author: Brian Quinlan (bquinlan) * (Python committer) | Date: 2009年04月18日 19:36 | |
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 |
|||
| msg86136 - (view) | Author: Georg Brandl (georg.brandl) * (Python committer) | Date: 2009年04月18日 20:02 | |
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. |
|||
| msg86138 - (view) | Author: Brian Quinlan (bquinlan) * (Python committer) | Date: 2009年04月18日 20:20 | |
OK, a bit on motivation: 1. datetime.timedelta instances are a convenient way of representing durations 2. datetime.timedelta instances cannot be conveniently used in many calculations e.g. calculating distance based on velocity and time 3. 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 |
|||
| msg86147 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年04月18日 23:49 | |
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. |
|||
| msg86148 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年04月18日 23:50 | |
Sorry for the last comment about unit tests, they are here actually :-) |
|||
| msg86167 - (view) | Author: Brian Quinlan (bquinlan) * (Python committer) | Date: 2009年04月19日 12:07 | |
Attached is a patch that implements .total_seconds as an instance method |
|||
| msg87768 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年05月14日 21:38 | |
Given the timing, I fear this will have to wait for 3.2. |
|||
| msg95726 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年11月25日 23:04 | |
The patch is committed in r76529 (trunk) and r76530 (py3k). Thank you! |
|||
| msg95732 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2009年11月26日 08:13 | |
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. |
|||
| msg95733 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2009年11月26日 08:14 | |
That should be t.total_seconds(), of course. |
|||
| msg95740 - (view) | Author: Antoine Pitrou (pitrou) * (Python committer) | Date: 2009年11月26日 12:17 | |
> 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) It would be less obvious, though. |
|||
| msg145928 - (view) | Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) | Date: 2011年10月19日 18:15 | |
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. |
|||
| msg146115 - (view) | Author: Mark Dickinson (mark.dickinson) * (Python committer) | Date: 2011年10月21日 19:28 | |
What about def total_minutes(td): return td / datetime.timedelta(minutes=1) ? |
|||
| msg146131 - (view) | Author: Brian Quinlan (bquinlan) * (Python committer) | Date: 2011年10月21日 20:34 | |
You'll probably get more traction if you file a new bug. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:56:47 | admin | set | github: 50038 |
| 2011年10月21日 20:34:13 | bquinlan | set | messages: + msg146131 |
| 2011年10月21日 19:28:00 | mark.dickinson | set | messages: + msg146115 |
| 2011年10月19日 18:15:31 | giampaolo.rodola | set | nosy:
+ giampaolo.rodola messages: + msg145928 |
| 2009年11月26日 12:17:24 | pitrou | set | messages: + msg95740 |
| 2009年11月26日 08:14:15 | mark.dickinson | set | messages: + msg95733 |
| 2009年11月26日 08:13:12 | mark.dickinson | set | nosy:
+ mark.dickinson messages: + msg95732 |
| 2009年11月25日 23:04:49 | pitrou | set | status: open -> closed resolution: fixed messages: + msg95726 stage: patch review -> resolved |
| 2009年05月14日 21:38:17 | pitrou | set | messages:
+ msg87768 versions: + Python 3.2, - Python 3.1 |
| 2009年05月14日 21:36:34 | pitrou | set | nosy:
+ mw44118 |
| 2009年05月14日 21:36:29 | pitrou | link | issue6020 superseder |
| 2009年04月19日 12:07:17 | bquinlan | set | messages: + msg86167 |
| 2009年04月19日 12:06:07 | bquinlan | set | files: + totalseconds2.diff |
| 2009年04月18日 23:50:45 | pitrou | set | messages: + msg86148 |
| 2009年04月18日 23:50:02 | pitrou | set | priority: normal type: enhancement stage: patch review |
| 2009年04月18日 23:49:48 | pitrou | set | nosy:
+ pitrou messages: + msg86147 versions: + Python 2.7, - Python 3.0 |
| 2009年04月18日 20:20:25 | bquinlan | set | messages: + msg86138 |
| 2009年04月18日 20:02:59 | georg.brandl | set | messages: + msg86136 |
| 2009年04月18日 19:36:41 | bquinlan | set | messages: + msg86135 |
| 2009年04月18日 19:22:13 | georg.brandl | set | nosy:
+ georg.brandl messages: + msg86133 |
| 2009年04月18日 18:38:43 | bquinlan | set | files:
+ totalseconds.diff keywords: + patch |
| 2009年04月18日 18:37:39 | bquinlan | create | |