mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2024-11-22 07:11: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(".", "-")
|
datestr = date.replace(".", "-")
|
||||||
try:
|
try:
|
||||||
samedate = datetime.date.fromisoformat(datestr)
|
samedate = datetime.date.fromisoformat(datestr)
|
||||||
|
return samedate
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Could be in std euro format e.g. 14/07/2023
|
# 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)
|
match = re.search(r'(\d{1,2})/(\d{1,2})/(\d{2,4})', datestr)
|
||||||
@ -37,19 +38,22 @@ def make_valid_date(date):
|
|||||||
except:
|
except:
|
||||||
print(f"! - Fail, tried to decompose date in dd/mm/yyyy format but failed: {datestr=} ")
|
print(f"! - Fail, tried to decompose date in dd/mm/yyyy format but failed: {datestr=} ")
|
||||||
return None
|
return None
|
||||||
# probably a single digit day number. HACKUS MAXIMUS.
|
# probably a single digit day number or month number
|
||||||
datestr = datestr[:-1] + "0" + datestr[-1]
|
match = re.search(r'(\d{4})-(\d{1,2})-(\d{1,2})', datestr)
|
||||||
# datestr = f"{datestr:02d}"
|
if match:
|
||||||
print(f"! - ValueError, trying.. {datestr=} ")
|
y = int(match.group(1))
|
||||||
try:
|
m = int(match.group(2))
|
||||||
samedate = datetime.date.fromisoformat(datestr)
|
d = int(match.group(3))
|
||||||
except:
|
|
||||||
try:
|
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:
|
except:
|
||||||
print(f"! - ValueError, FAILED {datestr=} ")
|
print(f"! - Fail, tried to decompose date in yyyy-mm-d or yyy-m-dd format but failed: {datestr=} ")
|
||||||
samedate = None
|
return None
|
||||||
return samedate
|
|
||||||
|
print(f"! - Failed to understand date, none of our tricks worked {datestr=} ")
|
||||||
|
return None
|
||||||
|
|
||||||
class Wallet(models.Model):
|
class Wallet(models.Model):
|
||||||
"""We do not keep the JSON values in the database, we query them afresh each time,
|
"""We do not keep the JSON values in the database, we query them afresh each time,
|
||||||
|
Loading…
Reference in New Issue
Block a user