@@ -292,7 +292,7 @@ def array_strptime(ndarray[object] values, object fmt,
292
292
break
293
293
elif parse_code == 19 :
294
294
z = found_dict[' z' ]
295
- gmtoff, gmtoff_fraction = _parse_timezone_directive (z)
295
+ gmtoff, gmtoff_fraction = parse_timezone_directive (z)
296
296
297
297
# If we know the wk of the year and what day of that wk, we can figure
298
298
# out the Julian day of the year.
@@ -656,7 +656,7 @@ cdef _calc_julian_from_U_or_W(int year, int week_of_year,
656
656
days_to_week = week_0_length + (7 * (week_of_year - 1 ))
657
657
return 1 + days_to_week + day_of_week
658
658
659
- cdef _parse_timezone_directive (object z):
659
+ cdef parse_timezone_directive (object z):
660
660
"""
661
661
Parse the '%z ' directive and return an offset from UTC
662
662
@@ -674,22 +674,23 @@ cdef _parse_timezone_directive(object z):
674
674
object gmtoff_remainder, gmtoff_remainder_padding
675
675
676
676
if z == ' Z' :
677
- gmtoff = 0
678
- gmtoff_fraction = 0
677
+ return (0 , 0 )
679
678
else :
680
- if z[3 ] == ' :' :
681
- z = z[:3 ] + z[4 :]
682
- if len (z) > 5 :
683
- if z[5 ] != ' :' :
684
- msg = " Inconsistent use of : in {0}"
685
- raise ValueError (msg.format(z))
686
- z = z[:5 ] + z[6 :]
687
- hours = int (z[1 :3 ])
688
- minutes = int (z[3 :5 ])
689
- seconds = int (z[5 :7 ] or 0 )
690
- gmtoff = (hours * 60 * 60 ) + (minutes * 60 ) + seconds
691
- gmtoff_remainder = z[8 :]
692
-
679
+ try :
680
+ if z[3 ] == ' :' :
681
+ z = z[:3 ] + z[4 :]
682
+ if len (z) > 5 :
683
+ if z[5 ] != ' :' :
684
+ msg = " Inconsistent use of : in {0}"
685
+ raise ValueError (msg.format(z))
686
+ z = z[:5 ] + z[6 :]
687
+ hours = int (z[1 :3 ])
688
+ minutes = int (z[3 :5 ])
689
+ seconds = int (z[5 :7 ] or 0 )
690
+ gmtoff = (hours * 60 * 60 ) + (minutes * 60 ) + seconds
691
+ gmtoff_remainder = z[8 :]
692
+ except ValueError :
693
+ raise ValueError (" Could not parse offset: {0}" .format(z))
693
694
# Pad to always return microseconds.
694
695
pad_number = 6 - len (gmtoff_remainder)
695
696
gmtoff_remainder_padding = " 0" * pad_number
@@ -698,5 +699,4 @@ cdef _parse_timezone_directive(object z):
698
699
if z.startswith(" -" ):
699
700
gmtoff = - gmtoff
700
701
gmtoff_fraction = - gmtoff_fraction
701
-
702
- return (gmtoff, gmtoff_fraction)
702
+ return (gmtoff, gmtoff_fraction)
0 commit comments