With this I'm struggling for some hours now. The code is much larger than the example I'm providing here, but it breaks down to this:
I have a datetime object that is naive and I want to convert it to UTC time, but that doesn't work as expected.
import datetime
import pytz
# Following is a naive datetime object, but we know the user meant
# timezone Europe/Zurich
zurich = datetime.datetime(2016, 1, 8, 7, 10)
# datetime.datetime(2016, 1, 8, 7, 10)
# So I'm now converting it to a datetime object which is aware of the
# timezone
zurich = zurich.replace(tzinfo=pytz.timezone('Europe/Zurich'))
# datetime.datetime(2016, 1, 8, 7, 10, tzinfo=<DstTzInfo 'Europe/Zurich' BMT+0:30:00 STD>)
# Let's convert to UTC
zurich = zurich.astimezone(pytz.utc)
# datetime.datetime(2016, 1, 8, 6, 40, tzinfo=<UTC>)
The offset of Zurich compared to UTC time is +01:00 (Daylight saving time) or +02:00 (Summer time). Why is Python thinking it is +00:30?!
Any help is highly appreciated (I'm starting to pull out my hair already).