1
- from cpython.datetime cimport tzinfo
2
1
from datetime import timezone
2
+ from cpython.datetime cimport tzinfo, PyTZInfo_Check, PyDateTime_IMPORT
3
+ PyDateTime_IMPORT
3
4
4
5
# dateutil compat
5
6
from dateutil.tz import (
@@ -29,20 +30,20 @@ cdef tzinfo utc_pytz = UTC
29
30
30
31
# ----------------------------------------------------------------------
31
32
32
- cpdef inline bint is_utc(object tz):
33
+ cpdef inline bint is_utc(tzinfo tz):
33
34
return tz is utc_pytz or tz is utc_stdlib or isinstance (tz, _dateutil_tzutc)
34
35
35
36
36
- cdef inline bint is_tzlocal(object tz):
37
+ cdef inline bint is_tzlocal(tzinfo tz):
37
38
return isinstance (tz, _dateutil_tzlocal)
38
39
39
40
40
- cdef inline bint treat_tz_as_pytz(object tz):
41
+ cdef inline bint treat_tz_as_pytz(tzinfo tz):
41
42
return (hasattr (tz, ' _utc_transition_times' ) and
42
43
hasattr (tz, ' _transition_info' ))
43
44
44
45
45
- cdef inline bint treat_tz_as_dateutil(object tz):
46
+ cdef inline bint treat_tz_as_dateutil(tzinfo tz):
46
47
return hasattr (tz, ' _trans_list' ) and hasattr (tz, ' _trans_idx' )
47
48
48
49
@@ -59,7 +60,9 @@ cpdef inline object get_timezone(object tz):
59
60
the tz name. It needs to be a string so that we can serialize it with
60
61
UJSON/pytables. maybe_get_tz (below) is the inverse of this process.
61
62
"""
62
- if is_utc(tz):
63
+ if not PyTZInfo_Check(tz):
64
+ return tz
65
+ elif is_utc(tz):
63
66
return tz
64
67
else :
65
68
if treat_tz_as_dateutil(tz):
@@ -327,7 +330,7 @@ cpdef bint tz_compare(object start, object end):
327
330
return get_timezone(start) == get_timezone(end)
328
331
329
332
330
- def tz_standardize (tz: object ):
333
+ def tz_standardize (tz: tzinfo ):
331
334
"""
332
335
If the passed tz is a pytz timezone object, "normalize" it to the a
333
336
consistent version
0 commit comments