aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/pytz_deprecation_shim/_compat_py2.py
blob: f473d2676ce3123f2fe863bd9aa15cd76baa3219 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from datetime import timedelta

from dateutil import tz

UTC = tz.UTC


def get_timezone(key):
    if not key:
        raise KeyError("Unknown time zone: %s" % key)

    try:
        rv = tz.gettz(key)
    except Exception:
        rv = None

    if rv is None or not isinstance(rv, (tz.tzutc, tz.tzfile)):
        raise KeyError("Unknown time zone: %s" % key)

    return rv


def get_timezone_file(f, key=None):
    return tz.tzfile(f)


def get_fixed_offset_zone(offset):
    return tz.tzoffset(None, timedelta(minutes=offset))


def is_ambiguous(dt):
    return tz.datetime_ambiguous(dt)


def is_imaginary(dt):
    return not tz.datetime_exists(dt)


enfold = tz.enfold


def get_fold(dt):
    return getattr(dt, "fold", 0)