python / cpython

The Python programming language
https://www.python.org
Other
62.46k stars 29.98k forks source link

Adding a timedelta to an aware datetime object not resulting in the correct time being calculated #123487

Open ben-n93 opened 3 weeks ago

ben-n93 commented 3 weeks ago

Bug report

Bug description:

I am trying to understand why the time of the sydney_aedt object is not being adjusted to reflect the change in timezone offset:

import datetime
import zoneinfo

sydney_aest = datetime.datetime(2024, 8, 30, 15, 0, 0)
sydney_aest = sydney_aest.astimezone(zoneinfo.ZoneInfo("Australia/Sydney"))
print(sydney_aest)
sydney_aedt = sydney_aest + datetime.timedelta(days=90)
print(sydney_aedt)

Expected output:

2024-08-30 15:00:00+10:00
2024-11-28 16:00:00+11:00 # Clock moves forward an hour.

Actual output:

2024-08-30 15:00:00+10:00
2024-11-28 15:00:00+11:00 # Time is the same.

I would expected that with the change from AEST to AEDT the hour should move forward an hour however as you can see this is not the result.

CPython versions tested on:

3.12

Operating systems tested on:

macOS

rruuaanng commented 2 weeks ago

I'm sorry that I don't have a mac, but I will test it on win.