File: pytz.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 (18 lines) | stat: -rw-r--r-- 502 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import pytz

from .base import TimeZoneBackend, TimeZoneNotFoundError


class PYTZBackend(TimeZoneBackend):
    utc_tzobj = pytz.utc
    all_tzstrs = pytz.all_timezones
    base_tzstrs = pytz.common_timezones

    def is_tzobj(self, value):
        return value is pytz.UTC or isinstance(value, pytz.tzinfo.BaseTzInfo)

    def to_tzobj(self, tzstr):
        try:
            return pytz.timezone(tzstr)
        except pytz.UnknownTimeZoneError as err:
            raise TimeZoneNotFoundError from err