Python not only supports subtracting dates but also allows adding a timedelta to a datetime. Internally, timedelta objects are represented by three components: microseconds, seconds, and days.
from zoneinfo import ZoneInfo
from datetime import datetime, timedelta
berlin = ZoneInfo("Europe/Berlin")
sat = datetime(2024, 10, 26, 21, 0, tzinfo=berlin)
Let's add one day to Saturday at 9:00 PM (CEST). This operation will cross the daylight saving time boundary, bringing us to Sunday evening.
a = sat + timedelta(days=1)
b = sat + timedelta(hours=24)
Which statement about a
and b
is true?
Both are Sunday 9 pm
Both are Sunday 8 pm
a
is 9 pm, b
is 8 pm