File: __init__.py

package info (click to toggle)
python-django-timezone-field 7.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 292 kB
  • sloc: python: 1,047; sh: 6; makefile: 3
file content (25 lines) | stat: -rw-r--r-- 656 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from django import VERSION, conf

from .base import TimeZoneNotFoundError

USE_PYTZ_DEFAULT = getattr(conf.settings, "USE_DEPRECATED_PYTZ", VERSION < (4, 0))

tz_backend_cache = {}


def get_tz_backend(use_pytz):
    use_pytz = USE_PYTZ_DEFAULT if use_pytz is None else use_pytz
    if use_pytz not in tz_backend_cache:
        if use_pytz:
            from .pytz import PYTZBackend

            klass = PYTZBackend
        else:
            from .zoneinfo import ZoneInfoBackend

            klass = ZoneInfoBackend
        tz_backend_cache[use_pytz] = klass()
    return tz_backend_cache[use_pytz]


__all__ = ["TimeZoneNotFoundError", "get_tz_backend"]