From 551711fb3458fb1c63424086a4196c89f8a818cc Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Mon, 15 Dec 2025 15:56:27 +0000 Subject: [PATCH] cope with pre 2000 years --- core/models/wallets.py | 52 +++++------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/core/models/wallets.py b/core/models/wallets.py index c18af41..4567312 100644 --- a/core/models/wallets.py +++ b/core/models/wallets.py @@ -56,9 +56,12 @@ def make_valid_date(walletname, date): m = int(data['month']) y = int(data['year']) - # Two-digit year handling - if y < 2000: - y = y + 2000 + # Two-digit year handling: Use 70 as the pivot year (70-99 -> 19xx, 00-69 -> 20xx) + if y < 100: + if y >= 70: + y = 1900 + y + else: + y = 2000 + y try: samedate = datetime.date(y, m, d) @@ -99,49 +102,6 @@ def make_valid_date(walletname, date): return None - -# def make_valid_date(walletname, date): - # """Take whatever garbage some fool has typed in and try to make it into a valid ISO-format date - # """ - # datestr = date.replace(".", "-").replace("/", "-") - # try: - # samedate = datetime.date.fromisoformat(datestr) - # return samedate - # except ValueError: - # # Could be in std euro format e.g. 14/07/2023 - # match = re.search(r'(\d{1,2})/(\d{1,2})/(\d{2,4})', datestr) - # if match: - # d = int(match.group(1)) - # m = int(match.group(2)) - # y = int(match.group(3)) - # if y<2000: - # y = y + 2000 - # try: - # samedate = datetime.date(y, m, d) - # print(f"- - Warning, not in ISO format. '{datestr=}' but we tried to cope: {samedate.isoformat()} {walletname}") - # return samedate - # except: - # print(f"! - Fail, tried to decompose date in dd/mm/yyyy format but failed: {datestr=} ") - # return None - # # probably a single digit day number or month number - # match = re.search(r'(\d{4})-(\d{1,2})-(\d{1,2})', datestr) - # if match: - # y = int(match.group(1)) - # m = int(match.group(2)) - # d = int(match.group(3)) - # try: - # samedate = datetime.date(y, m, d) - # print(f"- - Warning, 1 digit only for month or day '{datestr=}' but we coped: {samedate.isoformat()} ") - # return samedate - # except: - # print(f"! - Fail, tried to decompose date in yyyy-mm-d or yyy-m-dd format but failed: {datestr=} ") - # return None - - # if datestr: # might have been None - # if datestr != "None": - # print(f"! - Failed to understand date, none of our tricks worked {datestr=} ") - # return None - archaic_wallets = [ '1984AndysNotebook', '1984BrownLandscapeNotebook',