Opened 5 years ago

Closed 5 years ago

#31595 closed Bug (invalid)

models.Datefield being localized where it shouldn't

Reported by: Akshay Salunke Owned by: nobody
Component: Internationalization Version: 2.2
Severity: Normal Keywords: DateField, chrome, date, format
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Akshay Salunke)

So, I have a DateField in my model and have also set I18N & L10N to True in settings. When a browser running en-AU locale visits the website, Django tries to parse the value read from model, using the first value in DATE_INPUT_FORMATS from /conf.

The bug is when a user in en-AU locale visits the website, Django reads the Datefield value from model and tries to localize it for en-AU locale (from DATE_INPUT_FORMATS in /conf/en_AU) to this format '%d/%m/%Y', but html5 requires the value for <input type="date"> to be explicitly in this format: yyyy-MM-dd. ref1 ref2

This causes an error in chrome dev console and the HTML date field rendered without the date read from the model.https://user-images.githubusercontent.com/2255284/82113682-326dc080-979b-11ea-8e7f-c442f30aae1f.png
https://user-images.githubusercontent.com/2255284/82113676-2255e100-979b-11ea-973b-564fdb4a3497.png

This bug goes away when I disable L10N in settings. I am able to reproduce this bug in en-AU and en-GB

Attachments (2)

datepicker-chrome.png (3.9 KB ) - added by Akshay Salunke 5 years ago.
This is how date picker looks in chrome when locale is en-AU even when this field has an initials value.
chrome-console-error.png (11.9 KB ) - added by Akshay Salunke 5 years ago.
Error in chrome dev console.

Download all attachments as: .zip

Change History (5)

by Akshay Salunke, 5 years ago

Attachment: datepicker-chrome.png added

This is how date picker looks in chrome when locale is en-AU even when this field has an initials value.

by Akshay Salunke, 5 years ago

Attachment: chrome-console-error.png added

Error in chrome dev console.

comment:1 by Akshay Salunke, 5 years ago

Description: modified (diff)

in reply to:  description comment:2 by Akshay Salunke, 5 years ago

Description: modified (diff)

Replying to akshaysalunke13:

So, I have a DateField in my model and have also set I18N & L10N to True in settings. When a browser running en-AU locale visits the website, Django tries to parse the value read from model, using the first value in DATE_INPUT_FORMATS from /conf.

The bug is when a user in en-AU locale visits the website, Django reads the Datefield value from model and tries to localize it for en-AU locale (from DATE_INPUT_FORMATS in /conf/en_AU) to this format '%d/%m/%Y', but html5 requires the value for <input type="date"> to be explicitly in this format: yyyy-MM-dd. [ref](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date) [ref2](https://developer.mozilla.org/en-US/docs/Web/HTML/Date_and_time_formats#Format_of_a_valid_date_string).

This causes an error in chrome dev console and the HTML date field rendered without the date read from the model.https://user-images.githubusercontent.com/2255284/82113682-326dc080-979b-11ea-8e7f-c442f30aae1f.png
https://user-images.githubusercontent.com/2255284/82113676-2255e100-979b-11ea-973b-564fdb4a3497.png

This bug goes away when I disable L10N in settings. I am able to reproduce this bug in en-AU and en-GB

comment:3 by Claude Paroz, 5 years ago

Resolution: invalid
Status: newclosed

AFAIK Django does not use type="date" for its widgets due to browser support being too variable. If you set it yourself, you should at least force the form fields initialized with localize=False. Anyway, this is entering support territory.

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