1- from cpython.datetime cimport tzinfo
21from datetime import timezone
2+ from cpython.datetime cimport tzinfo, PyTZInfo_Check, PyDateTime_IMPORT
3+ PyDateTime_IMPORT
34
45# dateutil compat
56from dateutil.tz import (
@@ -29,20 +30,20 @@ cdef tzinfo utc_pytz = UTC
2930
3031# ----------------------------------------------------------------------
3132
32- cpdef inline bint is_utc(object tz):
33+ cpdef inline bint is_utc(tzinfo tz):
3334 return tz is utc_pytz or tz is utc_stdlib or isinstance (tz, _dateutil_tzutc)
3435
3536
36- cdef inline bint is_tzlocal(object tz):
37+ cdef inline bint is_tzlocal(tzinfo tz):
3738 return isinstance (tz, _dateutil_tzlocal)
3839
3940
40- cdef inline bint treat_tz_as_pytz(object tz):
41+ cdef inline bint treat_tz_as_pytz(tzinfo tz):
4142 return (hasattr (tz, ' _utc_transition_times' ) and
4243 hasattr (tz, ' _transition_info' ))
4344
4445
45- cdef inline bint treat_tz_as_dateutil(object tz):
46+ cdef inline bint treat_tz_as_dateutil(tzinfo tz):
4647 return hasattr (tz, ' _trans_list' ) and hasattr (tz, ' _trans_idx' )
4748
4849
@@ -59,7 +60,9 @@ cpdef inline object get_timezone(object tz):
5960 the tz name. It needs to be a string so that we can serialize it with
6061 UJSON/pytables. maybe_get_tz (below) is the inverse of this process.
6162 """
62- if is_utc(tz):
63+ if not PyTZInfo_Check(tz):
64+ return tz
65+ elif is_utc(tz):
6366 return tz
6467 else :
6568 if treat_tz_as_dateutil(tz):
@@ -327,7 +330,7 @@ cpdef bint tz_compare(object start, object end):
327330 return get_timezone(start) == get_timezone(end)
328331
329332
330- def tz_standardize (tz: object ):
333+ def tz_standardize (tz: tzinfo ):
331334 """
332335 If the passed tz is a pytz timezone object, "normalize" it to the a
333336 consistent version
0 commit comments