@@ -371,9 +371,9 @@ def __init__(self, locale_time=None):
371371 # W is set below by using 'U'
372372 'y' : r"(?P<y>\d\d)" ,
373373 'Y' : r"(?P<Y>\d\d\d\d)" ,
374- # follow C99 specification of only parsing two digits for
374+ # follow C99 specification of parsing up to two digits for
375375 # first hundred centuries
376- 'C' : r"(?P<C>\d\d )" ,
376+ 'C' : r"(?P<C>\d{1,2} )" ,
377377 # See gh-121237: "z" must support colons for backwards compatibility.
378378 'z' : r"(?P<z>([+-]\d\d:?[0-5]\d(:?[0-5]\d(\.\d{1,6})?)?)|(?-i:Z))?" ,
379379 ':z' : r"(?P<colon_z>([+-]\d\d:[0-5]\d(:[0-5]\d(\.\d{1,6})?)?)|(?-i:Z))?" ,
@@ -617,6 +617,21 @@ def parse_int(s):
617617 year += 2000
618618 else :
619619 year += 1900
620+ elif group_key == 'C' and 'y' not in found_dict :
621+ # C99 support for century in [0,99] (years 0-9999).
622+ century = parse_int (found_dict [group_key ])
623+ year = century * 100
624+ if century > 0 :
625+ year = century * 100
626+ elif century == 0 :
627+ # ValueError fix, since MINYEAR = 1 in Lib/_pydatetime.py
628+ year = 1
629+ else :
630+ # in line with other format directives, negative numbers
631+ # are not supported by the regular expression;
632+ # this branch will not trigger!
633+ msg = f"Negative century unsupported ({ found_dict [group_key ]} )"
634+ raise ValueError (msg )
620635 elif group_key == 'Y' :
621636 year = int (found_dict ['Y' ])
622637 elif group_key == 'G' :
@@ -627,15 +642,6 @@ def parse_int(s):
627642 month = locale_time .f_month .index (found_dict ['B' ].lower ())
628643 elif group_key == 'b' :
629644 month = locale_time .a_month .index (found_dict ['b' ].lower ())
630- elif group_key == 'C' and 'y' not in found_dict :
631- # C99 support for century in [0,99] (years 0-9999).
632- century = parse_int (found_dict [group_key ])
633- year = century * 100
634- if century > 0 :
635- year = century * 100
636- else :
637- # ValueError fix, since MINYEAR = 1 in Lib/_pydatetime.py
638- year = 1
639645 elif group_key == 'd' :
640646 day = parse_int (found_dict ['d' ])
641647 elif group_key == 'H' :
0 commit comments