Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pendulum/tz/__init__.py: 62%
32 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 06:35 +0000
1from typing import Tuple
2from typing import Union
4import pytzdata
6from .local_timezone import get_local_timezone
7from .local_timezone import set_local_timezone
8from .local_timezone import test_local_timezone
9from .timezone import UTC
10from .timezone import FixedTimezone as _FixedTimezone
11from .timezone import Timezone as _Timezone
14PRE_TRANSITION = "pre"
15POST_TRANSITION = "post"
16TRANSITION_ERROR = "error"
18timezones = pytzdata.timezones # type: Tuple[str, ...]
21_tz_cache = {}
24def timezone(name, extended=True): # type: (Union[str, int], bool) -> _Timezone
25 """
26 Return a Timezone instance given its name.
27 """
28 if isinstance(name, int):
29 return fixed_timezone(name)
31 if name.lower() == "utc":
32 return UTC
34 if name in _tz_cache:
35 return _tz_cache[name]
37 tz = _Timezone(name, extended=extended)
38 _tz_cache[name] = tz
40 return tz
43def fixed_timezone(offset): # type: (int) -> _FixedTimezone
44 """
45 Return a Timezone instance given its offset in seconds.
46 """
47 if offset in _tz_cache:
48 return _tz_cache[offset] # type: ignore
50 tz = _FixedTimezone(offset)
51 _tz_cache[offset] = tz
53 return tz
56def local_timezone(): # type: () -> _Timezone
57 """
58 Return the local timezone.
59 """
60 return get_local_timezone()