2024-04-02 00:19:08 +02:00
|
|
|
from functools import cache
|
2017-03-14 10:53:09 +01:00
|
|
|
|
2022-06-28 00:43:57 +02:00
|
|
|
from scripts.lib.zulip_tools import get_tzdata_zi
|
2020-06-11 00:54:34 +02:00
|
|
|
|
2017-03-14 10:53:09 +01:00
|
|
|
|
2024-04-02 00:19:08 +02:00
|
|
|
@cache
|
2024-07-12 02:30:17 +02:00
|
|
|
def get_canonical_timezone_map() -> dict[str, str]:
|
2020-10-27 01:41:00 +01:00
|
|
|
canonical = {}
|
2022-06-28 00:43:57 +02:00
|
|
|
with get_tzdata_zi() as f:
|
2020-10-27 01:41:00 +01:00
|
|
|
for line in f:
|
2022-09-21 00:46:58 +02:00
|
|
|
fields = line.split()
|
|
|
|
if fields and "link".startswith(fields[0].lower()): # zic(8) accepts any prefix of Link
|
|
|
|
code, name, alias = fields
|
2020-10-27 01:41:00 +01:00
|
|
|
canonical[alias] = name
|
|
|
|
return canonical
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-10-27 01:41:00 +01:00
|
|
|
def canonicalize_timezone(key: str) -> str:
|
|
|
|
return get_canonical_timezone_map().get(key, key)
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
timezone: Correct common_timezones dictionary.
The changes are as follows:
• Fix one day offset in all western zones.
• Correct CST from -64800 to -21600 and CDT from -68400 to -18000.
• Disambiguate PST in favor of -28000 over +28000.
• Add GMT, UTC, WET, previously excluded for being at offset 0.
• Add ACDT, AEDT, AKST, MET, MSK, NST, NZDT, PKT, which the previous
code did not find.
• Remove numbered abbreviations -12, …, +14, which are unnecessary.
• Remove MSD and PKST, which are no longer used.
Hardcode the dict and verify it with a test, so that future
discrepancies won’t go silently unnoticed.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
2021-01-27 22:12:36 +01:00
|
|
|
# Note: some of these abbreviations are fundamentally ambiguous (see
|
|
|
|
# zerver/tests/test_timezone.py), so you should never rely on them as
|
|
|
|
# anything more than a heuristic.
|
|
|
|
common_timezones = {
|
|
|
|
"SST": -39600,
|
|
|
|
"HST": -36000,
|
|
|
|
"AKST": -32400,
|
|
|
|
"HDT": -32400,
|
|
|
|
"AKDT": -28800,
|
|
|
|
"PST": -28800,
|
|
|
|
"MST": -25200,
|
|
|
|
"PDT": -25200,
|
|
|
|
"CST": -21600,
|
|
|
|
"MDT": -21600,
|
|
|
|
"CDT": -18000,
|
|
|
|
"EST": -18000,
|
|
|
|
"AST": -14400,
|
|
|
|
"EDT": -14400,
|
|
|
|
"NST": -12600,
|
|
|
|
"ADT": -10800,
|
|
|
|
"NDT": -9000,
|
|
|
|
"GMT": 0,
|
|
|
|
"UTC": 0,
|
|
|
|
"WET": 0,
|
|
|
|
"BST": +3600,
|
|
|
|
"CET": +3600,
|
|
|
|
"MET": +3600,
|
|
|
|
"WAT": +3600,
|
|
|
|
"WEST": +3600,
|
|
|
|
"CAT": +7200,
|
|
|
|
"CEST": +7200,
|
|
|
|
"EET": +7200,
|
|
|
|
"MEST": +7200,
|
|
|
|
"SAST": +7200,
|
|
|
|
"EAT": +10800,
|
|
|
|
"EEST": +10800,
|
|
|
|
"IDT": +10800,
|
|
|
|
"MSK": +10800,
|
|
|
|
"PKT": +18000,
|
|
|
|
"IST": +19800,
|
|
|
|
"WIB": +25200,
|
|
|
|
"AWST": +28800,
|
|
|
|
"HKT": +28800,
|
|
|
|
"WITA": +28800,
|
|
|
|
"JST": +32400,
|
|
|
|
"KST": +32400,
|
|
|
|
"WIT": +32400,
|
|
|
|
"ACST": +34200,
|
|
|
|
"AEST": +36000,
|
|
|
|
"ChST": +36000,
|
|
|
|
"ACDT": +37800,
|
|
|
|
"AEDT": +39600,
|
|
|
|
"NZST": +43200,
|
|
|
|
"NZDT": +46800,
|
|
|
|
}
|