@@ -1165,7 +1165,12 @@ def parse_date(string, locale=LC_TIME, format='medium'):
11651165 if not numbers :
11661166 raise ParseError ("No numbers were found in input" )
11671167
1168- # TODO: try ISO format first?
1168+ # we try ISO-alike format first, meaning similar to YYYY-MM-DD
1169+ if len (numbers ) == 3 :
1170+ ints = list (map (int , numbers ))
1171+ if ints [0 ] > 31 and ints [1 ] <= 12 and ints [2 ] <= 31 :
1172+ return date (* ints )
1173+
11691174 format_str = get_date_format (format = format , locale = locale ).pattern .lower ()
11701175 year_idx = format_str .index ('y' )
11711176 month_idx = format_str .index ('m' )
@@ -1181,19 +1186,12 @@ def parse_date(string, locale=LC_TIME, format='medium'):
11811186 # names, both in the requested locale, and english
11821187
11831188 year = numbers [indexes ['Y' ]]
1184- day = numbers [indexes ['D' ]]
1185- month = numbers [indexes ['M' ]]
11861189 if len (year ) == 2 :
1187- # check if we don't have an ISO kind of format
1188- if len (day ) == 4 : # day first locale
1189- year , month , day = day , month , year
1190- elif len (month ) == 4 : # month first locale
1191- year , month , day = month , day , year
1192- else :
1193- year = 2000 + int (year )
1194- year = int (year )
1195- month = int (month )
1196- day = int (day )
1190+ year = 2000 + int (year )
1191+ else :
1192+ year = int (year )
1193+ month = int (numbers [indexes ['M' ]])
1194+ day = int (numbers [indexes ['D' ]])
11971195 if month > 12 :
11981196 month , day = day , month
11991197 return date (year , month , day )
0 commit comments