Skip to content

Commit

Permalink
Fixed #29089 -- Avoided redundant date parsing in SelectDateWidget.fo…
Browse files Browse the repository at this point in the history
…rmat_value().
  • Loading branch information
timgraham authored Jan 30, 2018
1 parent 3a4b118 commit 5538729
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions django/forms/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,17 +1004,17 @@ def format_value(self, value):
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)
except ValueError:
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
Expand Down

0 comments on commit 5538729

Please sign in to comment.