mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-21 23:01:52 +00:00
better fix for variant date formats
This commit is contained in:
parent
748cb91a20
commit
3c78ab79ca
@ -21,6 +21,7 @@ def make_valid_date(date):
|
||||
datestr = date.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)
|
||||
@ -37,19 +38,22 @@ def make_valid_date(date):
|
||||
except:
|
||||
print(f"! - Fail, tried to decompose date in dd/mm/yyyy format but failed: {datestr=} ")
|
||||
return None
|
||||
# probably a single digit day number. HACKUS MAXIMUS.
|
||||
datestr = datestr[:-1] + "0" + datestr[-1]
|
||||
# datestr = f"{datestr:02d}"
|
||||
print(f"! - ValueError, trying.. {datestr=} ")
|
||||
try:
|
||||
samedate = datetime.date.fromisoformat(datestr)
|
||||
except:
|
||||
# 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.fromisoformat(datestr[:10])
|
||||
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"! - ValueError, FAILED {datestr=} ")
|
||||
samedate = None
|
||||
return samedate
|
||||
print(f"! - Fail, tried to decompose date in yyyy-mm-d or yyy-m-dd format but failed: {datestr=} ")
|
||||
return None
|
||||
|
||||
print(f"! - Failed to understand date, none of our tricks worked {datestr=} ")
|
||||
return None
|
||||
|
||||
class Wallet(models.Model):
|
||||
"""We do not keep the JSON values in the database, we query them afresh each time,
|
||||
|
Loading…
Reference in New Issue
Block a user