-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Doing calculations with datetime
objects with zoneinfo
timezones doesn't work - they completely ignore the timezone. For example:
>>> LONDON = zoneinfo.ZoneInfo('Europe/London')
>>> d0 = datetime.datetime(2022, 3, 27, 0, tzinfo=LONDON)
>>> print(d0)
2022-03-27 00:00:00+00:00
>>> print(d0 + datetime.timedelta(seconds=3600+1800))
2022-03-27 01:30:00+00:00
2022-03-27 01:30 is a time that doesn't exist in the Europe/London timezone.
Similarly:
>>> d1 = datetime.datetime(2022, 3, 27, 3, tzinfo=LONDON)
>>> print(d1 - d0)
3:00:00
The difference between d1
and d0
is 2 hours, not 3 hours.
I guess this might not be fixable, in which case at the very least the datetime
module documentation needs to be updated to say that you simply cannot do arithmetic with datetime
objects unless they are timezone-naive or using the UTC timezone.
Your environment
- CPython versions tested on: 3.9
- Operating system and architecture: Ubuntu 20.04.4
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error