| 1 |
""" |
| 2 |
babel.localtime |
| 3 |
~~~~~~~~~~~~~~~ |
| 4 |
|
| 5 |
Babel specific fork of tzlocal to determine the local timezone |
| 6 |
of the system. |
| 7 |
|
| 8 |
:copyright: (c) 2013-2026 by the Babel Team. |
| 9 |
:license: BSD, see LICENSE for more details. |
| 10 |
""" |
| 11 |
|
| 12 |
import datetime |
| 13 |
import sys |
| 14 |
|
| 15 |
if sys.platform == 'win32': |
| 16 |
from babel.localtime._win32 import _get_localzone |
| 17 |
else: |
| 18 |
from babel.localtime._unix import _get_localzone |
| 19 |
|
| 20 |
|
| 21 |
# TODO(3.0): the offset constants are not part of the public API |
| 22 |
# and should be removed |
| 23 |
from babel.localtime._fallback import ( |
| 24 |
DSTDIFF, # noqa: F401 |
| 25 |
DSTOFFSET, # noqa: F401 |
| 26 |
STDOFFSET, # noqa: F401 |
| 27 |
ZERO, # noqa: F401 |
| 28 |
_FallbackLocalTimezone, |
| 29 |
) |
| 30 |
|
| 31 |
|
| 32 |
def get_localzone() -> datetime.tzinfo: |
| 33 |
"""Returns the current underlying local timezone object. |
| 34 |
Generally this function does not need to be used, it's a |
| 35 |
better idea to use the :data:`LOCALTZ` singleton instead. |
| 36 |
""" |
| 37 |
return _get_localzone() |
| 38 |
|
| 39 |
|
| 40 |
try: |
| 41 |
LOCALTZ = get_localzone() |
| 42 |
except LookupError: |
| 43 |
LOCALTZ = _FallbackLocalTimezone() |