I have a time object that is timezone naive. I also have a user specified timezone. My database stores the time object as UTC, so I'm trying to convert the time the user gives me to the UTC time. And then when I retrieve it, I'm trying to reverse the operation. However, after I reverse it I'm getting a different date then I started with.
import pytz
from datetime import datetime
timezone = 'US/Alaska'
start_date = datetime(2018, 7, 28, 10, 0, tzinfo=pytz.timezone(timezone))
# datetime.datetime(2018, 7, 28, 10, 0, tzinfo=<DstTzInfo 'US/Alaska' LMT-1 day, 14:00:00 STD>)
utc_datetime = start_date.astimezone(pytz.utc)
# datetime.datetime(2018, 7, 28, 12, 0, tzinfo=<DstTzInfo 'US/Alaska' AKDT-1 day, 16:00:00 DST>)
converted_back = utc_datetime.astimezone(pytz.utc)
# datetime.datetime(2018, 7, 28, 12, 0, tzinfo=<DstTzInfo 'US/Alaska' AKDT-1 day, 16:00:00 DST>)
start_date != converted_back