优化日期类处理
This commit is contained in:
@@ -27,11 +27,18 @@ def handle_date(string):
|
||||
|
||||
string = string.replace("年", "-").replace("月", "-").replace("日", "").replace("/", "-").replace(".", "-")
|
||||
string = re.sub(r'[^0-9-]', '', string)
|
||||
length = len(string)
|
||||
if length > 8 and "-" not in string:
|
||||
if "-" in string:
|
||||
string = string.strip("-")
|
||||
dash_count = string.count("-")
|
||||
if dash_count > 2:
|
||||
third_dash_index = string.find("-", string.find("-", string.find("-") + 1) + 1)
|
||||
string = string[:third_dash_index]
|
||||
day = string[string.rindex("-") + 1:]
|
||||
if len(day) > 2:
|
||||
string = string[:2 - len(day)]
|
||||
else:
|
||||
if len(string) > 8:
|
||||
string = string[:8]
|
||||
elif length > 10 and "-" in string:
|
||||
string = string[:10]
|
||||
|
||||
if len(string) < 6:
|
||||
return ""
|
||||
|
||||
Reference in New Issue
Block a user