pytz issue : tz_convert() does not give correct (summer) time in the future

Viewed 185

I am concerned about a weird behavior of pytz, using tz_convert() for dates in the future.

More precisely, given a UTC timestamp: '2046-05-31 22:00:00+00:00', converted to "Europe/Paris" timezone:

pd.to_datetime(pd.Index(pd.Series('2046-05-31 22:00:00+00:00'))).tz_convert('Europe/Paris')

returns

DatetimeIndex(['2046-05-31 23:00:00+01:00'], dtype='datetime64[ns, Europe/Paris]', freq=None)

while it should return

DatetimeIndex(['2046-06-01 00:00:00+02:00'], dtype='datetime64[ns, Europe/Paris]', freq=None)

pytz interprets June 2046 in Paris as a Central European Time (+01) instead of Central European Summer Time (+02). For instance, trying the above with '2026-05-31 22:00:00+00:00' returns CEST time. It seems the issue is that pytz does not know the dates of CEST and CET in the future.

This is problematic when trying to convert localized timestamp to a date at a particular place for instance.

Is that expected, and is there a way to avoid that issue ?

Note: even if pandas is involved, this seems like a pytz issue, as datetime.fromisoformat('2046-05-31 22:00:00+00:00').astimezone(pytz.timezone("Europe/Paris"))returns CET time and not CEST.

0 Answers
Related