As specified by the pytz documentation:
Unfortunately using the tzinfo argument of the standard datetime constructors ‘’does not work’’ with pytz for many timezones.
Indeed, this is not the expected result, the timezone is wrong:
>>> datetime(2013, 12, 27, 20, 0, 0, tzinfo=timezone('Europe/Bucharest'))
datetime.datetime(2013, 12, 27, 20, 0,
tzinfo=<DstTzInfo 'Europe/Bucharest' BMT+1:44:00 STD>)
This is explained the pytz
constructor given the timezone('Europe/Bucharest')
timezone does not check when the timezone offset should be considered, and these things tend to change over time. pytz
just uses the earlier known definition, which will often be wrong:
>>> timezone('Europe/Bucharest')
<DstTzInfo 'Europe/Bucharest' BMT+1:44:00 STD>
It looks like this timezone was used until 1931.
There is no such issue when working with UTC times and converting those using astimezone
(for display purposes only as recommended):
>>> datetime(2013, 12, 27, 20, 0, 0, tzinfo=pytz.utc)\
.astimezone(timezone('Europe/Bucharest'))
datetime.datetime(2013, 12, 27, 22, 0,
tzinfo=<DstTzInfo 'Europe/Bucharest' EET+2:00:00 STD>)
Then you get the expected result:
>>> datetime(2013, 12, 27, 20, 0, 0, tzinfo=pytz.utc)\
.astimezone(timezone('Europe/Bucharest'))\
.astimezone(timezone('Europe/Berlin'))\
.replace(tzinfo=None)
datetime.datetime(2013, 12, 27, 21, 0)