@@ -302,7 +302,7 @@ def __init__(self, locale_time=None):
302302 # W is set below by using 'U'
303303 'y' : r"(?P<y>\d\d)" ,
304304 'Y' : r"(?P<Y>\d\d\d\d)" ,
305- 'z' : r"(?P<z>[+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?|(?-i:Z))" ,
305+ 'z' : r"(?P<z>( [+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?) |(?-i:Z))? " ,
306306 'A' : self .__seqToRE (self .locale_time .f_weekday , 'A' ),
307307 'a' : self .__seqToRE (self .locale_time .a_weekday , 'a' ),
308308 'B' : self .__seqToRE (self .locale_time .f_month [1 :], 'B' ),
@@ -548,27 +548,28 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
548548 iso_week = int (found_dict ['V' ])
549549 elif group_key == 'z' :
550550 z = found_dict ['z' ]
551- if z == 'Z' :
552- gmtoff = 0
553- else :
554- if z [3 ] == ':' :
555- z = z [:3 ] + z [4 :]
556- if len (z ) > 5 :
557- if z [5 ] != ':' :
558- msg = f"Inconsistent use of : in { found_dict ['z' ]} "
559- raise ValueError (msg )
560- z = z [:5 ] + z [6 :]
561- hours = int (z [1 :3 ])
562- minutes = int (z [3 :5 ])
563- seconds = int (z [5 :7 ] or 0 )
564- gmtoff = (hours * 60 * 60 ) + (minutes * 60 ) + seconds
565- gmtoff_remainder = z [8 :]
566- # Pad to always return microseconds.
567- gmtoff_remainder_padding = "0" * (6 - len (gmtoff_remainder ))
568- gmtoff_fraction = int (gmtoff_remainder + gmtoff_remainder_padding )
569- if z .startswith ("-" ):
570- gmtoff = - gmtoff
571- gmtoff_fraction = - gmtoff_fraction
551+ if z :
552+ if z == 'Z' :
553+ gmtoff = 0
554+ else :
555+ if z [3 ] == ':' :
556+ z = z [:3 ] + z [4 :]
557+ if len (z ) > 5 :
558+ if z [5 ] != ':' :
559+ msg = f"Inconsistent use of : in { found_dict ['z' ]} "
560+ raise ValueError (msg )
561+ z = z [:5 ] + z [6 :]
562+ hours = int (z [1 :3 ])
563+ minutes = int (z [3 :5 ])
564+ seconds = int (z [5 :7 ] or 0 )
565+ gmtoff = (hours * 60 * 60 ) + (minutes * 60 ) + seconds
566+ gmtoff_remainder = z [8 :]
567+ # Pad to always return microseconds.
568+ gmtoff_remainder_padding = "0" * (6 - len (gmtoff_remainder ))
569+ gmtoff_fraction = int (gmtoff_remainder + gmtoff_remainder_padding )
570+ if z .startswith ("-" ):
571+ gmtoff = - gmtoff
572+ gmtoff_fraction = - gmtoff_fraction
572573 elif group_key == 'Z' :
573574 # Since -1 is default value only need to worry about setting tz if
574575 # it can be something other than -1.
0 commit comments