From 5cfbdd5a6e9d2ab248061e81ec77abc440f4e057 Mon Sep 17 00:00:00 2001 From: liuyebo <1515783401@qq.com> Date: Mon, 24 Jun 2024 13:28:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E6=9C=9F=E7=B1=BB?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- photo_review/util/data_util.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) 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 ""