Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#27981 closed Bug (fixed)

date/time filter docs inaccurate about how localization works

Reported by: Erdem Yılmaz Owned by: nobody
Component: Documentation Version: 1.10
Severity: Normal Keywords: template date filter
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the django documentation it says about date filter

When used without a format string:

{{ value|date }}

...the formatting string defined in the DATE_FORMAT setting will be used, without applying any localization.

my DATE_FORMAT in the settings.py is as follows:
DATE_FORMAT = 'd-F-Y'

But my DATE_FORMAT setting is not used, the locale-dictated format (DATE_FORMAT = 'd F Y') always overrides my custom format which contains dashes

Change History (11)

comment:1 by Tim Graham, 8 years ago

Component: Template systemDocumentation
Summary: date filter localization problemdate/time filter docs inaccurate about how localization works
Triage Stage: UnreviewedAccepted

It looks like this was an intentional change in #25758. Assuming that change shouldn't be reverted, the documentation should be updated as well as release notes for 1.10 added.

comment:2 by Claude Paroz, 8 years ago

Has patch: set

Suggested PR.

comment:3 by Erdem Yılmaz, 8 years ago

I want to ask why the change in #25758 shouldn't be reverted? I think if I set the settings.DATE_FORMAT it should be higher precendence then the locale dictated format in the date filter. Actually i think if i set the settings.DATE_FORMAT, all of the date fields in any part of the system should be displayed with this format instead of locale dictated one without applying the date filter. What is the reason of the locale-dictated format has higher precedence than the specified setting.DATE_FORMAT?

comment:4 by Claude Paroz, 8 years ago

Erdem, because when USE_L10N is True, all dates and numbers are now consistently localized by default. To prevent localization, you should be able to:

  • set USE_L10N to False to deactivate localization site-wide.
  • use the localize template tag to deactivate localization at specific places.
  • add a custom setting for your application and pass that setting to the date filter.

If you can provide a use case which is not covered by these abilities, please develop.

comment:5 by Erdem Yılmaz, 8 years ago

I just wanted to use localization and at the same time set a specific DATE_FORMAT option instead of the locale one. Your second and third

approaches can be used but they are not too useful beacuse I should find all date occurances and apply some filters, which is not a general system wide solution https://docs.djangoproject.com/en/1.10/topics/i18n/formatting/#creating-custom-format-files This custom format file structure helped me. Thanks

I just curious about why when USE_L10N is True, all dates and numbers are now consistently localized by default even if some format setting (DATE_FORMAT, TIME_FORMAT etc.) is present. In my opininon setting something explicitly in the settings.py should have higher precedence than a locale format

Version 0, edited 8 years ago by Erdem Yılmaz (next)

in reply to:  5 ; comment:6 by Claude Paroz, 8 years ago

I just curious about why when USE_L10N is True, all dates and numbers are now consistently localized by default even if some format setting (DATE_FORMAT, TIME_FORMAT etc.) is present. In my opininon setting something explicitly in the settings.py should have higher precedence than a locale format

DATE_FORMAT and TIME_FORMAT always have a value from the global settings (for the case where USE_L10N is False). So Django cannot know if the settings are redefined at project level.

in reply to:  6 comment:7 by Erdem Yılmaz, 8 years ago

Replying to Claude Paroz:

I just curious about why when USE_L10N is True, all dates and numbers are now consistently localized by default even if some format setting (DATE_FORMAT, TIME_FORMAT etc.) is present. In my opininon setting something explicitly in the settings.py should have higher precedence than a locale format

DATE_FORMAT and TIME_FORMAT always have a value from the global settings (for the case where USE_L10N is False). So Django cannot know if the settings are redefined at project level.

I'm curious about the case where USE_L10N is True

comment:8 by Tim Graham, 8 years ago

The documentation for DATE_FORMAT and similar is clear about the behavior, "if USE_L10N is set to True, then the locale-dictated format has higher precedence and will be applied instead."

From a quick look, this decision dates to the introduction of the USE_L10N setting in 9233d0426537615e06b78d28010d17d5a66adf44 (#7980).

comment:9 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 6585ebe:

Fixed #27981 -- Doc'd date/time filter l10n changes in refs #25758.

comment:10 by Tim Graham <timograham@…>, 8 years ago

In 28cf32b:

[1.11.x] Fixed #27981 -- Doc'd date/time filter l10n changes in refs #25758.

Backport of 6585ebebaaa58aeef45210a3119dbaa322f8baca from master

comment:11 by Tim Graham <timograham@…>, 8 years ago

In 16b97a2:

[1.10.x] Fixed #27981 -- Doc'd date/time filter l10n changes in refs #25758.

Backport of 6585ebebaaa58aeef45210a3119dbaa322f8baca from master

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