[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-25 Thread Elinaldo Monteiro


Elinaldo Monteiro  added the comment:

I am closed my issue.

--
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-24 Thread hongweipeng


Change by hongweipeng :


--
keywords: +patch
pull_requests: +15167
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/15481

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-22 Thread Michael Anckaert


Michael Anckaert  added the comment:

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  wrote:

>
> Paul Ganssle  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 
> 
> ___
>

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-22 Thread Paul Ganssle


Paul Ganssle  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-22 Thread Michael Anckaert


Michael Anckaert  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 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

--
nosy: +michaelanckaert

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-22 Thread Elinaldo Monteiro


Elinaldo Monteiro  added the comment:

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

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-22 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

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)

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-22 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +belopolsky, p-ganssle

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37914] class timedelta, support the method hours and minutes in field accessors

2019-08-22 Thread Elinaldo Monteiro


New submission from Elinaldo Monteiro :

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

--
messages: 350182
nosy: elinaldosoft
priority: normal
severity: normal
status: open
title: class timedelta, support the method hours and minutes in field accessors
type: enhancement
versions: Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com