Date input: allow yyyy-mm for iso format

This commit is contained in:
SNoiraud 2021-01-12 11:12:54 +01:00 committed by Nick Hall
parent 6d24ab7d75
commit 30a58130a5
2 changed files with 5 additions and 2 deletions

View File

@ -407,6 +407,9 @@ class DateDisplay:
if date_val[0] == date_val[1] == 0: if date_val[0] == date_val[1] == 0:
# No month and no day -> year # No month and no day -> year
value = year value = year
elif date_val[0] == 0:
# No day -> yyyy-mm
value = "%s-%02d" % (year, date_val[1])
else: else:
value = "%s-%02d-%02d" % (year, date_val[1], date_val[0]) value = "%s-%02d-%02d" % (year, date_val[1], date_val[0])
if date_val[2] < 0: if date_val[2] < 0:

View File

@ -481,7 +481,7 @@ class DateParser:
% self._smon_str, re.IGNORECASE) % self._smon_str, re.IGNORECASE)
self._numeric = re.compile( self._numeric = re.compile(
r"((\d+)[/\.]\s*)?((\d+)[/\.]\s*)?(\d+)\s*$") r"((\d+)[/\.]\s*)?((\d+)[/\.]\s*)?(\d+)\s*$")
self._iso = re.compile(r"(\d+)(/(\d+))?-(\d+)-(\d+)\s*$") self._iso = re.compile(r"(\d+)(/(\d+))?-(\d+)(-(\d+))?\s*$")
self._isotimestamp = re.compile( self._isotimestamp = re.compile(
r"^\s*?(\d{4})([01]\d)([0123]\d)(?:(?:[012]\d[0-5]\d[0-5]\d)|" r"^\s*?(\d{4})([01]\d)([0123]\d)(?:(?:[012]\d[0-5]\d[0-5]\d)|"
r"(?:\s+[012]\d:[0-5]\d(?::[0-5]\d)?))?\s*?$") r"(?:\s+[012]\d:[0-5]\d(?::[0-5]\d)?))?\s*?$")
@ -630,7 +630,7 @@ class DateParser:
groups = match.groups() groups = match.groups()
y = self._get_int(groups[0]) y = self._get_int(groups[0])
m = self._get_int(groups[3]) m = self._get_int(groups[3])
d = self._get_int(groups[4]) d = self._get_int(groups[5])
if groups[2] and julian_valid((d, m, y + 1)): if groups[2] and julian_valid((d, m, y + 1)):
return (d, m, y + 1, True) # slash year return (d, m, y + 1, True) # slash year
if check is None or check((d, m, y)): if check is None or check((d, m, y)):