1
1
""" Strptime-related classes and functions.
2
2
"""
3
+ from datetime import timezone
4
+
3
5
from cpython.datetime cimport (
4
6
PyDate_Check,
5
7
PyDateTime_Check,
6
8
date,
7
9
import_datetime,
10
+ timedelta,
8
11
tzinfo,
9
12
)
10
13
@@ -96,7 +99,7 @@ def array_strptime(
96
99
int week_of_year, week_of_year_start, parse_code, ordinal
97
100
int iso_week, iso_year
98
101
int64_t us, ns
99
- object val, group_key, ampm, found, timezone
102
+ object val, group_key, ampm, found, tz
100
103
bint is_raise = errors== " raise"
101
104
bint is_ignore = errors== " ignore"
102
105
bint is_coerce = errors== " coerce"
@@ -214,7 +217,7 @@ def array_strptime(
214
217
year = 1900
215
218
month = day = 1
216
219
hour = minute = second = ns = us = 0
217
- timezone = None
220
+ tz = None
218
221
# Default to -1 to signify that values not known; not critical to have,
219
222
# though
220
223
iso_week = week_of_year = - 1
@@ -304,9 +307,9 @@ def array_strptime(
304
307
# W starts week on Monday.
305
308
week_of_year_start = 0
306
309
elif parse_code == 17 :
307
- timezone = pytz.timezone(found_dict[" Z" ])
310
+ tz = pytz.timezone(found_dict[" Z" ])
308
311
elif parse_code == 19 :
309
- timezone = parse_timezone_directive(found_dict[" z" ])
312
+ tz = parse_timezone_directive(found_dict[" z" ])
310
313
elif parse_code == 20 :
311
314
iso_year = int (found_dict[" G" ])
312
315
elif parse_code == 21 :
@@ -388,7 +391,7 @@ def array_strptime(
388
391
continue
389
392
raise
390
393
391
- result_timezone[i] = timezone
394
+ result_timezone[i] = tz
392
395
393
396
return result, result_timezone.base
394
397
@@ -538,15 +541,15 @@ cdef (int, int) _calc_julian_from_V(int iso_year, int iso_week, int iso_weekday)
538
541
539
542
cdef tzinfo parse_timezone_directive(str z):
540
543
"""
541
- Parse the '%z ' directive and return a pytz.FixedOffset
544
+ Parse the '%z ' directive and return a datetime.timezone object.
542
545
543
546
Parameters
544
547
----------
545
548
z : string of the UTC offset
546
549
547
550
Returns
548
551
-------
549
- pytz.FixedOffset
552
+ datetime.timezone
550
553
551
554
Notes
552
555
-----
@@ -560,7 +563,7 @@ cdef tzinfo parse_timezone_directive(str z):
560
563
object gmtoff_remainder, gmtoff_remainder_padding
561
564
562
565
if z == " Z" :
563
- return pytz.FixedOffset( 0 )
566
+ return timezone(timedelta( 0 ) )
564
567
if z[3 ] == " :" :
565
568
z = z[:3 ] + z[4 :]
566
569
if len (z) > 5 :
@@ -580,4 +583,4 @@ cdef tzinfo parse_timezone_directive(str z):
580
583
total_minutes = ((hours * 60 ) + minutes + (seconds // 60 ) +
581
584
(microseconds // 60 _000_000))
582
585
total_minutes = - total_minutes if z.startswith(" -" ) else total_minutes
583
- return pytz.FixedOffset( total_minutes)
586
+ return timezone(timedelta( minutes = total_minutes) )
0 commit comments