Why does datetime.timedelta only have the attributes 'days' and 'seconds'?
Jon Ribbens
jon+usenet at unequivocal.eu
Sat Apr 16 18:49:29 EDT 2022
On 2022-04-16, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Sat, 16 Apr 2022 20:35:22 -0000 (UTC), Jon Ribbens
><jon+usenet at unequivocal.eu> declaimed the following:
>>I can categorically guarantee you it is not. But let's put it a
>>different way, if you like, if I want to add 24 hours, i.e. 86,400
>>seconds (or indeed any other fixed time period), to a timezone-aware
>>datetime in Python, how do I do it? It would appear that, without
>>converting to UTC before doing the calculation, you can't.
>
> Which is probably the recommended means to do just that.
Yes, as I've already mentioned it is good advice to always use UTC
when doing date/time calculations and only convert to another timezone
for display. However it is somewhat surprising that Python's datetime
simply *does not work* when doing arithmetic on timezone-aware objects.
It's not "disrecommended", it's straight-up broken.
> The only thing that is most noticeable about UTC is the incorporation
> of leap-seconds.
I've never yet managed to find an application where leap-seconds matter
;-)
More information about the Python-list
mailing list