def search(cls, name=None):
"""Resolve timezone given a name
``name`` can be:
* omitted or None: returns name of the local timezone via
tzlocal or UTC
* string matching a timezone name in ``pytz.all_timezones``:
returns the timezone name in proper case
* empty string ('') or wildcard regular expression ('.*'):
returns a list with all timezone names
* any other string: used as a regular expression; multiple or
zero matches returns a list with the matched timezone names
"""
if name == None:
try:
return tzlocal.get_localzone().zone
except:
return 'UTC'
if name in pytz.all_timezones:
return name
name_ = name.lower()
matches = []
for t in pytz.all_timezones:
t_ = t.lower()
if name_ == t_:
return t
if re.search(name, t) or re.search(name_, t_):
matches.append(t)
if len(matches) == 1:
return matches[0]
else:
return matches
# Error classes
评论列表
文章目录