I have the UTC offset in my DB for the users:
+5:30
How can I get the timezone abbreviation from this UTC offset using Python?
Such as
+5:30 => IST
Is it even possible to do this using Python?
I have the UTC offset in my DB for the users:
+5:30
How can I get the timezone abbreviation from this UTC offset using Python?
Such as
+5:30 => IST
Is it even possible to do this using Python?
As Matt stated, going from offset to timezone does not make a lot of sense.
In case you were looking to find an appropriate pytz.timezone object for a given offset:
there are timezones ranging from
"Etc/GMT-14"
to"Etc/GMT+12"
just take a look at
pytz.all_timezones
.Using those, I was able to use faulty client input (mistaking timezone for offset) to attach a valid timezone object to my user.
You can get a set (zero or more) of timezone abbreviations (as specified in the tz database) that corresponds to the given UTC offset now:
Output
If you want to get abbreviations including the historical data:
Output
This is not possible.
There are many time zones that share the same offset. See this Wikipedia article for details.
There is no uniform standard for time zone abbreviations. There are some listed here and here, and you can see that there are duplicates in both directions.
For example:
Read also the section "Time Zone != Offset" of the timezone tag wiki here on StackOverflow.