Why does datetime.timedelta only have the attributes 'days' and 'seconds'?
Lars Liedtke
lal at solute.de
Thu Apr 14 11:17:16 EDT 2022
Additionally, which datatype would you expect them to be returned in?
One could argument for int or float (Decimal?), both could be valid
datatypes, depending on how exact you might want them, while the second
is the time base of SI units.
Cheers
Lars
--
Lars Liedtke
Software Entwickler
Phone:
Fax: +49 721 98993-
E-mail: lal at solute.de
solute GmbH
Zeppelinstraße 15
76185 Karlsruhe
Germany
Marken der solute GmbH | brands of solute GmbH
billiger.de | Shopping.de
Geschäftsführer | Managing Director: Dr. Thilo Gans, Bernd Vermaaten
Webseite | www.solute.de
Sitz | Registered Office: Karlsruhe
Registergericht | Register Court: Amtsgericht Mannheim
Registernummer | Register No.: HRB 110579
USt-ID | VAT ID: DE234663798
Informationen zum Datenschutz | Information about privacy policy
http://solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php
Am 14.04.22 um 17:01 schrieb Paul Bryan:
> I think because minutes and hours can easily be composed by multiplying
> seconds. days is separate because you cannot compose days from seconds;
> leap seconds are applied to days at various times, due to
> irregularities in the Earth's rotation.
>
> On Thu, 2022-04-14 at 15:38 +0200, Loris Bennett wrote:
>> "Loris Bennett" <loris.bennett at fu-berlin.de> writes:
>>
>>> Hi,
>>>
>>> With Python 3.9.2 I get
>>>
>>> $ import datetime
>>> $ s = "1-00:01:01"
>>> $ t = datetime.datetime.strptime(s, "%d-%H:%M:%S")
>>> $ d = datetime.timedelta(days=t.day, hours=t.hour,
>>> minutes=t.minute, seconds=t.second)
>>> $ d.days
>>> 1
>>> $ d.seconds
>>> 61
>>> $ d.minutes
>>> AttributeError: 'datetime.timedelta' object has no attribute
>>> 'minutes'
>>>
>>> Is there a particular reason why there are no attributes 'minutes'
>>> and
>>> 'hours and the attribute 'seconds' encompasses is the entire
>>> fractional
>>> day?
>> That should read:
>>
>> Is there a particular reason why there are no attributes 'minutes'
>> and
>> 'hours' and the attribute 'seconds' encompasses the entire
>> fractional
>> day?
>>
>>> Cheers,
>>>
>>> Loris
>> --
>> Dr. Loris Bennett (Herr/Mr)
>> ZEDAT, Freie Universität Berlin Email
>> loris.bennett at fu-berlin.de
More information about the Python-list
mailing list