[Django] #25024: Discrepancy between /admin/ DateTimePicker.js date format and SHORT_DATE_FORMAT in /en/ lang

15 views
Skip to first unread message

Django

unread,
Jun 25, 2015, 11:15:44 AM6/25/15
to django-...@googlegroups.com
#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 | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
A question:

DateTimeShortcuts.js uses `get_format('DATE_INPUT_FORMATS')[0]` while the
rest of a Django application uses `SHORT_DATE_FORMAT` to format dates.

https://github.com/django/django/blob/master/django/conf/locale/en/formats.py#L13
https://github.com/django/django/blob/master/django/contrib/admin/static/admin/js/admin/DateTimeShortcuts.js#L330

Shouldn't formats.py be adjusted so `DATE_INPUT_FORMATS` holds
`'%m/%d/%Y'` which is equal to SHORT_DATE_FORMAT (`'m/d/Y'`)?

Further, I believe that the datepicker ignores the USE_L10N setting as
well (assuming it to be True). At least it used to in previous Django
versions.

Not sure whether to categorize under i18n or admin..

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

Django

unread,
Jun 25, 2015, 1:38:59 PM6/25/15
to django-...@googlegroups.com
#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
-------------------------------+--------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Could you clarify the current behavior vs. the expected behavior? Is the
issue related to #23049?

--
Ticket URL: <https://code.djangoproject.com/ticket/25024#comment:1>

Django

unread,
Jun 25, 2015, 5:42:20 PM6/25/15
to django-...@googlegroups.com
#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

unread,
Jun 30, 2015, 8:24:44 AM6/30/15
to django-...@googlegroups.com
#25024: Discrepancy between /admin/ DateTimePicker.js date format and
SHORT_DATE_FORMAT in /en/ lang
--------------------------------------+------------------------------------
Reporter: wdoekes | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Internationalization | Version: 1.8
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* type: Bug => Cleanup/optimization
* component: Uncategorized => Internationalization
* stage: Unreviewed => Accepted


Comment:

Well, these values are being formatted in input boxes so I don't think
it's illogical to use `DATE_INPUT_FORMATS`. Maybe your idea of trying to
use the value from `SHORT_DATE_FORMAT` has some merit, but we'll have to
see a patch to assess feasibility and what complexity this might add. I'm
not much of an expert in this area, but I'll tentatively accept the ticket
pending input from others.

--
Ticket URL: <https://code.djangoproject.com/ticket/25024#comment:3>

Reply all
Reply to author
Forward
0 new messages