如何处理 pytz 的 POSIX 时区信息(如 CST)?

How to handle POSIX timezone information (like CST) for pytz?

我有时区字符串 'CST' 并尝试在 pytz 内使用它。

不幸的是,这失败了:

cst = pytz.timezone('CST')

File "/home/user/venv/numba/lib/python3.6/site-packages/pytz/__init__.py", line 181, in timezone
  raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: 'CST'

我该怎么做才能避免这个错误?

import pytz


def valid_timezone(timezone):
    try:
        pytz.timezone(timezone)
    except pytz.exceptions.UnknownTimeZoneError:
        return False
    return True

if valid_timezone('CST'):
    # go ahead...
    pass
else:
    # not supported timezone..
    pass

CST 本身不是有效的时区标识符。

无法知道 CST 是否被解释为 (US) "Central Standard Time" (UTC-6)、"Cuba Standard Time" (UTC-5) 或 "China Standard Time" (UTC+8).

相反,传递完全合格的基于位置的 IANA time zone identifier,例如 America/ChicagoAmerica/HavanaAsia/Shanghai