dateutil icon indicating copy to clipboard operation
dateutil copied to clipboard

Going from winter- to summertime by adding a timedelta

Open frip opened this issue 3 years ago • 0 comments

Something seems to be wrong here:

>>> from dateutil import tz
>>> str(datetime(2022, 3, 27, 1, 45, tzinfo=tz.gettz("Europe/Vienna")))
'2022-03-27 01:45:00+01:00'
>>> str(datetime(2022, 3, 27, 1, 45, tzinfo=tz.gettz("Europe/Vienna")) + timedelta(minutes=20))
'2022-03-27 02:05:00+02:00'

The problem becomes clearer if we convert the results to UTC:

>>> str(datetime(2022, 3, 27, 1, 45, tzinfo=tz.gettz("Europe/Vienna")).astimezone(tz.UTC))
'2022-03-27 00:45:00+00:00'
>>> str((datetime(2022, 3, 27, 1, 45, tzinfo=tz.gettz("Europe/Vienna")) + timedelta(minutes=20)).astimezone(tz.UTC))
'2022-03-27 00:05:00+00:00'

In other words: By adding 20 minutes we go 40 minutes into the past.

I don't know if this is a problem of the timezone returned by tz.gettz("Europe/Vienna"), or the +-operator of timedelta, or my expectations when using timezones, but it is confusing, to say the least.

frip avatar Apr 13 '22 06:04 frip