Opened 10 years ago

Closed 9 months ago

#23049 closed Bug (fixed)

Admin DateField doesn't support all DATE_INPUT_FORMATS

Reported by: Patrick Dwyer <pat@…> Owned by: Sarah Boyce
Component: contrib.admin Version: 1.6
Severity: Normal Keywords:
Cc: Ed Henderson, Sarah Boyce Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

According to the documentation formats listed at http://docs.python.org/library/datetime.html#strftime-strptime-behavior are supported as DATE_INPUT_FORMATS. I have started using the date format "Thu 17 Jul 2014" represented by '%a %d %b %Y' as my DATE_FORMAT and the first listed DATE_INPUT_FORMAT but I am having issues on admin pages. The date picker calendar popups don't work correctly.

On initial page load the date is formatted correctly. When selecting the 17th of July 2014 from the calendar instead of getting "Thu 17 Jul 2014" the field is populated with "undefined 17 undefined 2014".

Looking at the code in admin/static/js/core.js these are the supported format characters...

        c: this.toString(),
        d: this.getTwoDigitDate(),
        H: this.getTwoDigitHour(),
        I: this.getTwoDigitTwelveHour(),
        m: this.getTwoDigitMonth(),
        M: this.getTwoDigitMinute(),
        p: (this.getHours() >= 12) ? 'PM' : 'AM',
        S: this.getTwoDigitSecond(),
        w: '0' + this.getDay(),
        x: this.toLocaleDateString(),
        X: this.toLocaleTimeString(),
        y: ('' + this.getFullYear()).substr(2, 4),
        Y: '' + this.getFullYear(),
        '%' : '%'

I think an "almost core" part of Django like admin should support what is documented or the documentation should be updated to reflect the actual behaviour.

I'm writing a simple fix for my own use. Although I'd be happy to start working on a real fix but don't want to waste time if this won't be considered.

Change History (8)

comment:1 by Patrick Dwyer, 10 years ago

Without much investigation this could be tricky to implement in a way that was locale aware (that could be the reason this hasn't been done already).

comment:2 by Patrick Dwyer, 10 years ago

I've just checked against the current master and stable/1.7.x branches and they seem to have the same limitation.

comment:3 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Ed Henderson, 9 years ago

Cc: Ed Henderson added

The latest documentation does not claim that all of the Python date formats are supported.

There is a specific list of formats supported by default, which does not include the format you are using.

What documentation leads you to believe that all of the formats should be supported?

comment:5 by Sarah Boyce, 10 months ago

Cc: Sarah Boyce added

comment:6 by Sarah Boyce, 9 months ago

Has patch: set
Owner: changed from nobody to Sarah Boyce
Status: newassigned
Last edited 9 months ago by Mariusz Felisiak (previous) (diff)

comment:7 by Mariusz Felisiak, 9 months ago

Triage Stage: AcceptedReady for checkin

comment:8 by Mariusz Felisiak <felisiak.mariusz@…>, 9 months ago

Resolution: fixed
Status: assignedclosed

In 531f557:

Fixed #23049 -- Added %a and %A support to Date.strftime.

This enables the admin to display the day as locale's abbreviated/full
name if %a/%A is used in the date format.

Note: See TracTickets for help on using tickets.
Back to Top