Example Code
from datetime import datetime, timezone
import pytz
tzstring = 'Europe/Berlin'
t1 = datetime(2016, 6, 16, 2, 0, tzinfo=pytz.timezone(tzstring))
t2 = datetime(2016, 6, 16, 2, 0, tzinfo=timezone.utc).astimezone(pytz.timezone(tzstring))
Observed
print(t1): 2016-06-16 02:00:00+00:53
print(t2): 2016-06-16 04:00:00+02:00
Expected
print(t1): 2016-06-16 04:00:00+02:00 # does not match expectation
print(t2): 2016-06-16 04:00:00+02:00 # matches expectation
Question
Can somebody please explain that to me?
Other questions:
- Why doesn't pytz localize() produce a datetime object with tzinfo matching the tz object that localized it? only asks for an explanation to "where in the code does it come from". My question is more in the direction: "Why is it that off?" - so likely a bit of history will be in an answer that I accept.