@@ -527,11 +527,11 @@ cdef class _TSObject:
527527 def __get__ (self ):
528528 return self .value
529529
530- cpdef _get_utcoffset(tzinfo):
530+ cpdef _get_utcoffset(tzinfo, obj ):
531531 try :
532532 return tzinfo._utcoffset
533533 except AttributeError :
534- return tzinfo.utcoffset(None )
534+ return tzinfo.utcoffset(obj )
535535
536536# helper to extract datetime and int64 from several different possibilities
537537cpdef convert_to_tsobject(object ts, object tz = None ):
@@ -570,20 +570,22 @@ cpdef convert_to_tsobject(object ts, object tz=None):
570570 ts = tz.normalize(ts)
571571 obj.value = _pydatetime_to_dts(ts, & obj.dts)
572572 obj.tzinfo = ts.tzinfo
573- elif tz is not pytz.utc :
573+ elif not _is_utc(tz) :
574574 ts = tz.localize(ts)
575575 obj.value = _pydatetime_to_dts(ts, & obj.dts)
576- obj.value -= _delta_to_nanoseconds(_get_utcoffset(ts.tzinfo))
576+ offset = _get_utcoffset(ts.tzinfo, ts)
577+ obj.value -= _delta_to_nanoseconds(offset)
577578 obj.tzinfo = ts.tzinfo
578579 else :
579580 # UTC
580581 obj.value = _pydatetime_to_dts(ts, & obj.dts)
581- obj.tzinfo = tz
582+ obj.tzinfo = pytz.utc
582583 else :
583584 obj.value = _pydatetime_to_dts(ts, & obj.dts)
584585 obj.tzinfo = ts.tzinfo
585586 if obj.tzinfo is not None and not _is_utc(obj.tzinfo):
586- obj.value -= _delta_to_nanoseconds(_get_utcoffset(obj.tzinfo))
587+ offset = _get_utcoffset(obj.tzinfo, obj)
588+ obj.value -= _delta_to_nanoseconds()
587589 _check_dts_bounds(obj.value, & obj.dts)
588590 return obj
589591 elif PyDate_Check(ts):
@@ -1028,15 +1030,15 @@ def _get_deltas(tz):
10281030 # tzoffset not hashable in Python 3
10291031 hash (tz)
10301032 except TypeError :
1031- num = int (total_seconds(_get_utcoffset(tz))) * 1000000000
1033+ num = int (total_seconds(_get_utcoffset(tz, None ))) * 1000000000
10321034 return np.array([num], dtype = np.int64)
10331035
10341036 if tz not in utc_offset_cache:
10351037 if hasattr (tz, ' _utc_transition_times' ):
10361038 utc_offset_cache[tz] = _unbox_utcoffsets(tz._transition_info)
10371039 else :
10381040 # static tzinfo
1039- num = int (total_seconds(_get_utcoffset(tz))) * 1000000000
1041+ num = int (total_seconds(_get_utcoffset(tz, None ))) * 1000000000
10401042 utc_offset_cache[tz] = np.array([num], dtype = np.int64)
10411043 return utc_offset_cache[tz]
10421044
0 commit comments