#25024: Discrepancy between /admin/ DateTimePicker.js date format and
SHORT_DATE_FORMAT in /en/ lang
-------------------------------+--------------------------------------
     Reporter:  wdoekes        |                    Owner:  nobody
         Type:  Bug            |                   Status:  new
    Component:  Uncategorized  |                  Version:  1.8
     Severity:  Normal         |               Resolution:
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by wdoekes):

 Hi tim, thanks for the quick response.

 Related to #23049? Somewhat.

 - That ticket says: when changing DATE_INPUT_FORMATS, certain strftime-
 parameters are broken/unusable from Javascript.
 - This ticket says: the default DATE_INPUT_FORMATS does not match up with
 the default (SHORT_)DATE_FORMAT.

 To clarify: DATE_INPUT_FORMATS is supposedly should be used as input, but
 it's also used for output: in DateTimeShortcuts.js and as default value in
 the DateInput widget.

 Expected behaviour:
 - DateTimeShortcut datepicker uses (SHORT_)DATE_FORMAT.
 Observed behaviour:
 - DateTimeShortcut datepicker and the DateInput widget use
 DATE_INPUT_FORMATS[0] (because of the strftime notation), but that zeroth
 value (%Y-%m-%d) is unequal to the default (SHORT_)DATE_FORMAT (m/d/Y).
 **This becomes inconsistent when you want to format dates in other places
 using the `|date` filter.**

 Possible fix 1:

 - Sync the value with the SHORT_DATE_FORMAT.
 {{{
 -    '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y',  # '2006-10-25', '10/25/2006',
 '10/25/06'
 +    '%m/%d/%Y', '%Y-%m-%d', '%m/%d/%y',  # '10/25/2006', '2006-10-25',
 '10/25/06'
 }}}

 Although the bug may be in wrongly using the *input* formats for *output*.
 So the better fix might be 2:

 - Use the output value instead of the zeroth element of allowed inputs.
 {{{
 -            var format = get_format('DATE_INPUT_FORMATS')[0];
 +            var format = get_format('DATE_FORMAT'); /* or
 SHORT_DATE_FORMAT? */
 +            format = format.replace(/([A-Za-z])/g, '%$1');
 ...
 (and fixes for _format_value() in widgets.py, so DATE_FORMAT is used as
 initial-value-format)
 }}}

 Possible fix 3:

 - Add a separate php-style date format for DATE_INPUTS_FORMATS[0], so I
 can consistently output values in the same format as the DateField widget,
 e.g.:
 {{{
  DATE_FORMAT = 'N j, Y'
 +DATE_OUTPUT_FORMAT = 'Y-m-d'
 ...
  DATE_INPUT_FORMATS = [
      '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y',  # '2006-10-25', '10/25/2006',
 '10/25/06'
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25024#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.bfebe67041181993b26da64603a9c317%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to