Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#26275 closed Cleanup/optimization (fixed)

Clarify the meaning of the `date` filter's 'o' formatter

Reported by: Igor Rashnitsov Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords: 1.7.11 template filter
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

On 1.7.11

>>> from datetime import datetime
>>> from django.template.defaultfilters import date
>>> date(datetime(2016, 1, 1, 0), 'F o')
u'January 2015'

(instead of 'January 2016')

Settings:

USE_TZ = False
TIME_ZONE = 'UTC'
LANGUAGE_CODE = 'en-us'
USE_I18N = True
USE_L10N = True

Change History (8)

comment:1 by Claude Paroz, 8 years ago

Component: UncategorizedDocumentation
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

I think that's the problem of your format string. Basically, you are asking: "Show me the month of that date (F) and then the year corresponding to the ISO week for that date (o)". So you are juxtaposing two values which don't make sense together. You should use 'Y' for the year in this case.

We could add a note in the documentation for o (at least "See also Y"), because people might browse the list of formatters (https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#date) and stop at the first letter that match their initial intention, without understanding the real meaning of o.

comment:2 by Quentin Fulsher, 8 years ago

I added a note about the meaning of the o specifier. I added it to my django fork here
https://github.com/inondle/django/blob/master/docs/ref/templates/builtins.txt#L1296

Does that look good or are there any improvements I could make?

comment:3 by Claude Paroz, 8 years ago

Thanks, can you make it a pull request?

comment:4 by Quentin Fulsher, 8 years ago

comment:5 by Simon Charette, 8 years ago

Has patch: set
Version: master

comment:6 by Tim Graham, 8 years ago

Summary: defaultfilter `date` incorrectly formatsClarify the meaning of the `date` filter's 'o' formatter

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

Resolution: fixed
Status: newclosed

In 5fb9756e:

Fixed #26275 -- Noted difference between o and Y date format chars.

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

In e96cdc6:

[1.9.x] Fixed #26275 -- Noted difference between o and Y date format chars.

Backport of 5fb9756eba01237cc0e550da689b9b79c51c96ed from master

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