@@ -5,7 +5,7 @@ import cython
5
5
from cython import Py_ssize_t
6
6
7
7
from cpython.datetime cimport (
8
- PyDateTime_IMPORT, PyDelta_Check, datetime, tzinfo)
8
+ PyDateTime_IMPORT, PyDelta_Check, datetime, timedelta, tzinfo)
9
9
PyDateTime_IMPORT
10
10
11
11
import pytz
@@ -421,23 +421,22 @@ cdef int64_t[:] _tz_convert_one_way(int64_t[:] vals, tzinfo tz, bint to_utc):
421
421
converted : ndarray[int64_t]
422
422
"""
423
423
cdef:
424
- int64_t[:] converted, result
424
+ int64_t[:] converted
425
425
Py_ssize_t i, n = len (vals)
426
426
int64_t val
427
427
428
- if not is_utc(tz):
428
+ if is_utc(tz):
429
+ converted = vals
430
+ elif is_tzlocal(tz):
429
431
converted = np.empty(n, dtype = np.int64)
430
- if is_tzlocal(tz):
431
- for i in range (n):
432
- val = vals[i]
433
- if val == NPY_NAT:
434
- converted[i] = NPY_NAT
435
- else :
436
- converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc)
437
- else :
438
- converted = _tz_convert_dst(vals, tz, to_utc)
432
+ for i in range (n):
433
+ val = vals[i]
434
+ if val == NPY_NAT:
435
+ converted[i] = NPY_NAT
436
+ else :
437
+ converted[i] = _tz_convert_tzlocal_utc(val, tz, to_utc)
439
438
else :
440
- converted = vals
439
+ converted = _tz_convert_dst( vals, tz, to_utc)
441
440
442
441
return converted
443
442
@@ -471,11 +470,12 @@ cdef inline int64_t _tzlocal_get_offset_components(int64_t val, tzinfo tz,
471
470
npy_datetimestruct dts
472
471
datetime dt
473
472
int64_t delta
473
+ timedelta td
474
474
475
475
dt64_to_dtstruct(val, & dts)
476
476
dt = datetime(dts.year, dts.month, dts.day, dts.hour,
477
477
dts.min, dts.sec, dts.us)
478
- # get_utcoffset ( tz.utcoffset under the hood) only makes sense if datetime
478
+ # tz.utcoffset only makes sense if datetime
479
479
# is _wall time_, so if val is a UTC timestamp convert to wall time
480
480
if not to_utc:
481
481
dt = dt.replace(tzinfo = tzutc())
@@ -484,7 +484,8 @@ cdef inline int64_t _tzlocal_get_offset_components(int64_t val, tzinfo tz,
484
484
if fold is not NULL :
485
485
fold[0 ] = dt.fold
486
486
487
- return int (get_utcoffset(tz, dt).total_seconds()) * 1000000000
487
+ td = tz.utcoffset(dt)
488
+ return int (td.total_seconds() * 1 _000_000_000)
488
489
489
490
490
491
cdef int64_t _tz_convert_tzlocal_utc(int64_t val, tzinfo tz, bint to_utc = True ,
0 commit comments