I'm writing a backend web API in Python. It the database, I have a datetime value, expressed in UTC (example: 2020-12-04 18:50+00:00), which represents the date/time that an event happend. In the backend, I want to convert this to local time and return that to the UI.
The UI has included in the request headers the browser's current timezone, expressed as a string containing the timezone name (in this example, it's "PDT"), as well as its current UTC offset in hours (-7)", which is correct, as it's currently Daylight Saving Time here.
I can convert that date/time to PDT easily by subtracting 7 hours. So, this gives me 2020-12-04 11:50-07:00.
But wait! That event occurred back in December, when it WASN'T Daylight Saving time. So, what I really want to return is 2020-12-04 10:50-08:00, because that represents that time it was in the browser's timezone at the time the "event" occurred. It was actually PST then, not PDT.
So, the answer I'm really trying to get is:
"At 2020-12-04 18:50 UTC, what time was it in the timezone region that 'PDT' represents, accounting for whether or not it was actually Daylight Saving time there on that date".
I suppose this could be broken down into 3 steps/questions:
Q1: What geographic (DST-naive) timezone does "PDT" represent?
A: America/Los_Angeles
Q2: What was the UTC offset in "America/Los_Angeles" on 2020-12-04?
A: UTC-8
Q3: What is 2020-12-04 18:50+00:00 in UTC-8?
A: 2020-12-04 10:50-08:00
Q3 is easy.
How can I achieve Q1 and Q2 using the Python libraries?
(BTW, we're using Python 3.7.12 and can't upgrade right now, so we don't have access to the zoneinfo library)