diff --git a/photo_review/util/data_util.py b/photo_review/util/data_util.py index b4ac2a8..dd26895 100644 --- a/photo_review/util/data_util.py +++ b/photo_review/util/data_util.py @@ -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: - string = string[:8] - elif length > 10 and "-" in string: - string = string[:10] + 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] if len(string) < 6: return ""