Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Imports
3from pytz import BaseTzInfo, UnknownTimeZoneError
4from .choices import ALL_TIMEZONE_CHOICES
5from .constants import ALL_TIMEZONES
7# Exports
9__all__ = (
10 "get_timezone_label",
11 "is_pytz_instance",
12 "is_valid_timezone",
13)
15# Functions
18def get_timezone_label(code):
19 """Get the label for the timezone.
21 :param code: The pytz timezone code.
22 :type code: str
24 :rtype: str
25 :raise: UnknownTimeZoneError
27 """
28 for value, label in ALL_TIMEZONE_CHOICES:
29 if code == value:
30 return label
32 raise UnknownTimeZoneError("Invalid or unrecognized timezone: %s" % code)
35def is_pytz_instance(value):
36 """Determines whether the given value is a BaseTzInfo instance.
38 :rtype: bool
40 """
41 return isinstance(value, BaseTzInfo)
44def is_valid_timezone(code):
45 """Determines whether the given code is a valid pytz timezone code.
47 :param code: The pytz timezone code.
48 :type code: str
50 :rtype: bool
52 """
53 return code in ALL_TIMEZONES