I would like to do create a pandas date range ranging from a parsed time to the current time, both in UTC. This is my best effort so far:
import dateutil
from datetime import datetime, timezone
start_time = dateutil.parser.isoparse ('2021-01-01T00Z')
end_time = datetime.now (timezone.utc)
Both timestamps are in the UTC timezone now, but creating the date range fails nevertheless:
> timestamps = pd.date_range (start=start_time, end=end_time, freq='H')
TypeError: Start and end cannot both be tz-aware with different timezones
Cause is that the tzinfo objects of both timestaps are UTC like, but of different types:
> print (start_time, end_time, type (start_time.tzinfo), type (end_time.tzinfo))
datetime.datetime(2020, 1, 1, 0, 0, tzinfo=tzutc()),
datetime.datetime(2021, 5, 13, 5, 45, 56, 866181, tzinfo=datetime.timezone.utc),
dateutil.tz.tz.tzutc,
datetime.timezone
So I'm stuck here. Is there a valid way to do this ? This could be either by parsing an ISO time format in UTC via 'datetime' or getting the current system time in UTC via dateutil. I did not find a solution for any of these.
Edit: Copy/paste error in the code examples