forked from ScoDoc/ScoDoc
modernise conversion date
This commit is contained in:
parent
84b02edd48
commit
8d72229e8b
@ -459,49 +459,22 @@ def dictfilter(d, fields, filter_nulls=True):
|
|||||||
# --- Misc Tools
|
# --- Misc Tools
|
||||||
|
|
||||||
|
|
||||||
def DateDMYtoISO(dmy, null_is_empty=False):
|
def DateDMYtoISO(dmy: str, null_is_empty=False) -> str:
|
||||||
"convert date string from french format to ISO"
|
"convert date string from french format to ISO"
|
||||||
if not dmy:
|
if not dmy:
|
||||||
if null_is_empty:
|
if null_is_empty:
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
if not isinstance(dmy, str):
|
if hasattr(dmy, "strftime"):
|
||||||
return dmy.strftime("%Y-%m-%d")
|
return dmy.strftime("%Y-%m-%d")
|
||||||
|
if not isinstance(dmy, str):
|
||||||
t = dmy.split("/")
|
raise ScoValueError(f'Date (j/m/a) invalide: "{dmy}"')
|
||||||
|
try:
|
||||||
if len(t) != 3:
|
dt = datetime.datetime.strptime(dmy, "%d/%m/%Y")
|
||||||
raise ScoValueError('Format de date (j/m/a) invalide: "%s"' % str(dmy))
|
except ValueError as exc:
|
||||||
day, month, year = t
|
raise ScoValueError(f'Date (j/m/a) invalide: "{dmy}"') from exc
|
||||||
year = int(year)
|
return dt.date().isoformat()
|
||||||
month = int(month)
|
|
||||||
day = int(day)
|
|
||||||
# accept years YYYY or YY, uses 1970 as pivot
|
|
||||||
if year < 100:
|
|
||||||
if year > 70:
|
|
||||||
year += 1900
|
|
||||||
else:
|
|
||||||
year += 2000
|
|
||||||
|
|
||||||
if month < 1 or month > 12:
|
|
||||||
raise ScoValueError("mois de la date invalide ! (%s)" % month)
|
|
||||||
# compute nb of day in month:
|
|
||||||
mo = month
|
|
||||||
if mo > 7:
|
|
||||||
mo = mo + 1
|
|
||||||
if mo % 2:
|
|
||||||
MonthNbDays = 31
|
|
||||||
elif mo == 2:
|
|
||||||
if year % 4 == 0 and ((year % 100 != 0) or (year % 400 == 0)):
|
|
||||||
MonthNbDays = 29 # leap
|
|
||||||
else:
|
|
||||||
MonthNbDays = 28
|
|
||||||
else:
|
|
||||||
MonthNbDays = 30
|
|
||||||
if day < 1 or day > MonthNbDays:
|
|
||||||
raise ScoValueError("jour de la date invalide ! (%s)" % day)
|
|
||||||
return "%04d-%02d-%02d" % (year, month, day)
|
|
||||||
|
|
||||||
|
|
||||||
def DateISOtoDMY(isodate):
|
def DateISOtoDMY(isodate):
|
||||||
|
@ -1991,7 +1991,6 @@ def formsemestre_bulletins_mailetuds(
|
|||||||
"""
|
"""
|
||||||
prefer_mail_perso = int(prefer_mail_perso)
|
prefer_mail_perso = int(prefer_mail_perso)
|
||||||
formsemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
formsemestre = FormSemestre.query.get_or_404(formsemestre_id)
|
||||||
nt: NotesTableCompat = res_sem.load_formsemestre_results(formsemestre)
|
|
||||||
inscriptions = [
|
inscriptions = [
|
||||||
inscription
|
inscription
|
||||||
for inscription in formsemestre.inscriptions
|
for inscription in formsemestre.inscriptions
|
||||||
|
Loading…
Reference in New Issue
Block a user