The current implementation first attempts to parse `value` as a
`datetime`.
Regardless of the outcome here it then parses `value` again against
against a regex.
Current implementation:
{{{
elif isinstance(value, str):
if 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}
}}}
With default settings `input_format` is (essentially) the same as the
`date_re`. We end up doing the work twice.
Should we not skip the `re.match` block if the `strptime` approach already
succeeded?
--
Ticket URL: <https://code.djangoproject.com/ticket/29089>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* has_patch: 0 => 1
* stage: Unreviewed => Accepted
Comment:
[https://github.com/django/django/pull/9638 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29089#comment:1>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29089#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"5538729e4ec1adf1c79d94c2b47b5dcf591ad94b" 5538729e]:
{{{
#!CommitTicketReference repository=""
revision="5538729e4ec1adf1c79d94c2b47b5dcf591ad94b"
Fixed #29089 -- Avoided redundant date parsing in
SelectDateWidget.format_value().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29089#comment:3>