Currently working on a project where I need to manipulate a particular store's opening and closing times to UTC in Python. The opening and closing times are date independent.
For instance , I have a opening/closing times as
00:00:00
00:10:00
I'd like to convert this time to UTC
20:00:00 UTC
20:10:00 UTC
and compare the result with the store times noted in a database to identify if a store was open in the open/close times it should have been open in.
I've used the following code to convert these
local_tmz = pytz.timezone(y["timezone_str"])
time_str_start = x["start_time_local"]
time_format = "%H:%M:%S"
naive_start_time = datetime.strptime(time_str_start,time_format)
local_start_time = local_tmz.localize(naive_start_time,is_dst=None)
utc_start_time=local_start_time.astimezone(pytz.utc)
print(utc_start_time.strftime(time_format),x["start_time_local"] ,y["timezone_str"])
y = Object containing timezone info of a particular store_id(In this case America/New_York)
x = Object containing opening/closing times of the particular store.
The output however is like so
4:56:00
The time conversion is off by an hour.