@@ -292,7 +292,7 @@ def array_strptime(ndarray[object] values, object fmt,
292292 break
293293 elif parse_code == 19 :
294294 z = found_dict[' z' ]
295- gmtoff, gmtoff_fraction = _parse_timezone_directive (z)
295+ gmtoff, gmtoff_fraction = parse_timezone_directive (z)
296296
297297 # If we know the wk of the year and what day of that wk, we can figure
298298 # out the Julian day of the year.
@@ -656,7 +656,7 @@ cdef _calc_julian_from_U_or_W(int year, int week_of_year,
656656 days_to_week = week_0_length + (7 * (week_of_year - 1 ))
657657 return 1 + days_to_week + day_of_week
658658
659- cdef _parse_timezone_directive (object z):
659+ cdef parse_timezone_directive (object z):
660660 """
661661 Parse the '%z ' directive and return an offset from UTC
662662
@@ -674,22 +674,23 @@ cdef _parse_timezone_directive(object z):
674674 object gmtoff_remainder, gmtoff_remainder_padding
675675
676676 if z == ' Z' :
677- gmtoff = 0
678- gmtoff_fraction = 0
677+ return (0 , 0 )
679678 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))
693694 # Pad to always return microseconds.
694695 pad_number = 6 - len (gmtoff_remainder)
695696 gmtoff_remainder_padding = " 0" * pad_number
@@ -698,5 +699,4 @@ cdef _parse_timezone_directive(object z):
698699 if z.startswith(" -" ):
699700 gmtoff = - gmtoff
700701 gmtoff_fraction = - gmtoff_fraction
701-
702- return (gmtoff, gmtoff_fraction)
702+ return (gmtoff, gmtoff_fraction)
0 commit comments