@@ -527,11 +527,11 @@ cdef class _TSObject:
527
527
def __get__ (self ):
528
528
return self .value
529
529
530
- cpdef _get_utcoffset(tzinfo):
530
+ cpdef _get_utcoffset(tzinfo, obj ):
531
531
try :
532
532
return tzinfo._utcoffset
533
533
except AttributeError :
534
- return tzinfo.utcoffset(None )
534
+ return tzinfo.utcoffset(obj )
535
535
536
536
# helper to extract datetime and int64 from several different possibilities
537
537
cpdef convert_to_tsobject(object ts, object tz = None ):
@@ -570,20 +570,22 @@ cpdef convert_to_tsobject(object ts, object tz=None):
570
570
ts = tz.normalize(ts)
571
571
obj.value = _pydatetime_to_dts(ts, & obj.dts)
572
572
obj.tzinfo = ts.tzinfo
573
- elif tz is not pytz.utc :
573
+ elif not _is_utc(tz) :
574
574
ts = tz.localize(ts)
575
575
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)
577
578
obj.tzinfo = ts.tzinfo
578
579
else :
579
580
# UTC
580
581
obj.value = _pydatetime_to_dts(ts, & obj.dts)
581
- obj.tzinfo = tz
582
+ obj.tzinfo = pytz.utc
582
583
else :
583
584
obj.value = _pydatetime_to_dts(ts, & obj.dts)
584
585
obj.tzinfo = ts.tzinfo
585
586
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()
587
589
_check_dts_bounds(obj.value, & obj.dts)
588
590
return obj
589
591
elif PyDate_Check(ts):
@@ -1028,15 +1030,15 @@ def _get_deltas(tz):
1028
1030
# tzoffset not hashable in Python 3
1029
1031
hash (tz)
1030
1032
except TypeError :
1031
- num = int (total_seconds(_get_utcoffset(tz))) * 1000000000
1033
+ num = int (total_seconds(_get_utcoffset(tz, None ))) * 1000000000
1032
1034
return np.array([num], dtype = np.int64)
1033
1035
1034
1036
if tz not in utc_offset_cache:
1035
1037
if hasattr (tz, ' _utc_transition_times' ):
1036
1038
utc_offset_cache[tz] = _unbox_utcoffsets(tz._transition_info)
1037
1039
else :
1038
1040
# static tzinfo
1039
- num = int (total_seconds(_get_utcoffset(tz))) * 1000000000
1041
+ num = int (total_seconds(_get_utcoffset(tz, None ))) * 1000000000
1040
1042
utc_offset_cache[tz] = np.array([num], dtype = np.int64)
1041
1043
return utc_offset_cache[tz]
1042
1044
0 commit comments