- Python Home
- About
- News
- Documentation
- Downloads
- Community
- Foundation
- Developer's Guide
- Issue Tracker
- Issues
- Summaries
- User
- Administration
- Help
Issue37914
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 2019-08-22 10:48 by elinaldosoft, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 15481 | closed | hongweipeng, 2019-08-25 03:14 | |
| Messages (7) | |||
|---|---|---|---|
| msg350182 - (view) | Author: Elinaldo Monteiro (elinaldosoft) | Date: 2019-08-22 10:48 | |
Hello,
Does it make sense to exist theses 2 methods in class timedelta?
@property
def hours(self):
return self._seconds // 3600
@property
def minutes(self):
return self._seconds // 60
|
|||
| msg350187 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-08-22 11:52 | |
It was already proposed several times before. The problem is that what do you expect to get from timedelta(hours=24).hours? The idiomatic way to convert a timedelta object to a number of hours is: td = timedelta(...) number_of_hours = td // timedelta(hours=1) |
|||
| msg350188 - (view) | Author: Elinaldo Monteiro (elinaldosoft) | Date: 2019-08-22 12:08 | |
Imagine the following scenario. from datetime import timedelta diff = timedelta(hours=23, minutes=59) - timedelta(hours=20, minutes=45) Which is the simplest ? diff.hours diff.total_seconds() // 3600 |
|||
| msg350198 - (view) | Author: Michael Anckaert (michaelanckaert) * | Date: 2019-08-22 15:35 | |
I would support this addition. The timedelta class already has accessors for days and seconds, why not for hours and minutes? The implementation should make use of the idiomatic way as Serhiy mentioned. >>> timedelta(hours=25).seconds // 3600 1 Is wrong, it should be >>> timedelta(hours=25) // timedelta(hours=1) 25 >>> timedelta(hours=24) // timedelta(hours=1) 24 |
|||
| msg350200 - (view) | Author: Paul Ganssle (p-ganssle) * ![]() |
Date: 2019-08-22 15:46 | |
> I would support this addition. The timedelta class already has accessors for days and seconds, why not for hours and minutes?
The `timedelta.days` and `timedelta.seconds` accessors do not do what is being requested here. The component accessors just give you a given component of the timedelta in its normalized form, so:
>>> td = timedelta(hours=25, minutes=1, seconds=2)
>>> td.days
1
>>> td.seconds
3662
>>> td // timedelta(seconds=1)
90062
The reason there is no hours or minutes is that the normalized form of timedelta doesn't have those components. It would be inconsistent to have `hours` and `minutes` give the total duration of the timedelta in the chosen units while `.days` and `.seconds` return just the component of the normalized form.
What's really being asked for here are `total_hours()` and `total_minutes()` methods, and when that has come up in the past (including recently on the python-dev mailing list), we've largely decided that the "divide by the units you want" idiom is sufficient (and in fact better in that you can choose any arbitrary units rather than just the ones that have specific names).
|
|||
| msg350201 - (view) | Author: Michael Anckaert (michaelanckaert) * | Date: 2019-08-22 15:50 | |
Thank you for the clarification Paul. It makes sense to me now to not include those accessors. On Thu, 22 Aug 2019 at 17:46, Paul Ganssle <report@bugs.python.org> wrote: > > Paul Ganssle <p.ganssle@gmail.com> added the comment: > > > I would support this addition. The timedelta class already has accessors > for days and seconds, why not for hours and minutes? > > The `timedelta.days` and `timedelta.seconds` accessors do not do what is > being requested here. The component accessors just give you a given > component of the timedelta in its normalized form, so: > > >>> td = timedelta(hours=25, minutes=1, seconds=2) > >>> td.days > 1 > >>> td.seconds > 3662 > >>> td // timedelta(seconds=1) > 90062 > > > The reason there is no hours or minutes is that the normalized form of > timedelta doesn't have those components. It would be inconsistent to have > `hours` and `minutes` give the total duration of the timedelta in the > chosen units while `.days` and `.seconds` return just the component of the > normalized form. > > What's really being asked for here are `total_hours()` and > `total_minutes()` methods, and when that has come up in the past (including > recently on the python-dev mailing list), we've largely decided that the > "divide by the units you want" idiom is sufficient (and in fact better in > that you can choose any arbitrary units rather than just the ones that have > specific names). > > ---------- > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue37914> > _______________________________________ > |
|||
| msg350451 - (view) | Author: Elinaldo Monteiro (elinaldosoft) | Date: 2019-08-25 12:51 | |
I am closed my issue. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:19 | admin | set | github: 82095 |
| 2019-08-25 12:51:46 | elinaldosoft | set | status: open -> closed resolution: rejected messages: + msg350451 stage: patch review -> resolved |
| 2019-08-25 03:14:11 | hongweipeng | set | keywords:
+ patch stage: patch review pull_requests: + pull_request15167 |
| 2019-08-22 15:50:12 | michaelanckaert | set | messages: + msg350201 |
| 2019-08-22 15:46:25 | p-ganssle | set | messages: + msg350200 |
| 2019-08-22 15:35:14 | michaelanckaert | set | nosy:
+ michaelanckaert messages: + msg350198 |
| 2019-08-22 12:08:13 | elinaldosoft | set | messages: + msg350188 |
| 2019-08-22 11:52:11 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg350187 |
| 2019-08-22 10:51:30 | xtreak | set | nosy:
+ belopolsky, p-ganssle |
| 2019-08-22 10:48:13 | elinaldosoft | create | |


