Given a time zone abbreviation, is there a way to get a list of possible time zones?
Like IST
could mean one of the following:
- Asia/Kolkata (India)
- Asia/Tel_Aviv (Israel)
- Europe/Dublin (Ireland)
What I was looking for was a way to get ['Asia/Kolkata', 'Asia/Tel_Aviv', 'Europe/Dublin']
as output when 'IST'
is given as input.
I was hoping that there would a way using the standard modules itself. Can it be done with the new zoneinfo
module?
Being inspired by this answer, I did
from datetime import datetime as dt
import zoneinfo
s = zoneinfo.available_timezones()
d = dict()
for tz in s:
t = z.ZoneInfo(tz).tzname(dt.utcnow())
if t not in d:
d[t] = [tz]
else:
d[t].append(tz)
But this is giving 'PDT' as
'PDT': ['America/Ensenada',
'America/Santa_Isabel',
'Mexico/BajaNorte',
'US/Pacific-New',
'US/Pacific',
'America/Vancouver',
'PST8PDT',
'America/Tijuana',
'America/Los_Angeles',
and 'PST' as just
'PST': ['Asia/Manila'],
But wouldn't 'America/Los_Angeles' also come under 'PST' at some point (not right now but later on).
I'm obviously missing something, but couldn't understand what it is..
Can there be a way to get the list of possible timezones from a time zone abbreviation?