I seem to be having a weird issue. Maybe it's a bug in Python but I would be surprised if it was.
I'm trying to test converting a naive datetime to UTC by first timezone information to it:
import datetime
from pytz import timezone
naive_datetime = datetime.datetime.now()
local_datetime = naive_datetime.replace(tzinfo=timezone('Europe/London'))
utc_datetime = local_datetime.astimezone(timezone('UTC'))
print("Naive datetime:", naive_datetime)
print("Local datetime:", local_datetime)
print("UTC datetime: ", utc_datetime)
This is the output:
Naive datetime: 2020-05-14 11:46:44.637956
Local datetime: 2020-05-14 11:46:44.637956-00:01
UTC datetime: 2020-05-14 11:47:44.637956+00:00
Note that adding a "Local timezone" of 'Europe/London' adds -1 minute of offset, not +1 hour as I would expect resulting in a "UTC" time of the original time +1 minute not -1 hour.
Why is it adding a minute offset and how do I get this to do what I expect?