Fixed #29089 -- Avoided redundant date parsing in SelectDateWidget.format_value().

This commit is contained in:
Tim Graham 2018-01-30 18:11:05 -05:00 committed by GitHub
parent 3a4b11873a
commit 5538729e4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -1004,7 +1004,10 @@ class SelectDateWidget(Widget):
if isinstance(value, (datetime.date, datetime.datetime)):
year, month, day = value.year, value.month, value.day
elif isinstance(value, str):
if settings.USE_L10N:
match = self.date_re.match(value)
if match:
year, month, day = [int(val) for val in match.groups()]
elif settings.USE_L10N:
input_format = get_format('DATE_INPUT_FORMATS')[0]
try:
d = datetime.datetime.strptime(value, input_format)
@ -1012,9 +1015,6 @@ class SelectDateWidget(Widget):
pass
else:
year, month, day = d.year, d.month, d.day
match = self.date_re.match(value)
if match:
year, month, day = [int(val) for val in match.groups()]
return {'year': year, 'month': month, 'day': day}
@staticmethod