__init__.py 1.0 KB

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