Opened 5 months ago

Closed 4 months ago

Last modified 4 months ago

#31006 closed Cleanup/optimization (fixed)

Document how to escape a date/time format character for the |date and |time filters.

Reported by: Baptiste Mispelon Owned by: Ryan Cheley
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description (last modified by felixxm)

The current documentation for the date and time filters doesn't explain how to escape a format character.

It's only documented as part of the now template tag:

Note that you can backslash-escape a format string if you want to use the “raw” value. In this example, both “o” and “f” are backslash-escaped, because otherwise each is a format string that displays the year and the time, respectively:
It is the {% now "jS \o\f F" %}
This would display as “It is the 4th of September”.

Historically, the big table with all the available format characters used to be next to the documentation for {% now %} but it was moved at some point (to be with the documentation for |date.

I would suggest moving the paragraph about backslash escape under the table of all formats instead (or least duplicating it there too).

Change History (11)

comment:1 Changed 5 months ago by Ryan Cheley

Owner: changed from nobody to Ryan Cheley
Status: newassigned

comment:2 Changed 5 months ago by felixxm

Summary: Document how to escape a date/time format character for the |date and |time filtersDocument how to escape a date/time format character for the |date and |time filters.
Triage Stage: UnreviewedAccepted

date documentation contains an example with escaped format characters:

outputs 9 de Enero de 2008 (the DATE_FORMAT format specifier for the es locale is r'j \d\e F \d\e Y'.

so maybe we can add a short explanation to this example, e.g.:

outputs 9 de Enero de 2008 (the DATE_FORMAT format specifier for the es locale is r'j \d\e F \d\e Y'). Both “d” and “e” are backslash-escaped, because otherwise each is a format string that displays the day and the timezone name, respectively.

I also agree to duplicate backslash example to the time documentation.

comment:3 Changed 4 months ago by Ryan Cheley

I have made the requested change (I think) which can be found here PR

Last edited 4 months ago by felixxm (previous) (diff)

comment:4 Changed 4 months ago by felixxm

Description: modified (diff)
Has patch: set

comment:5 Changed 4 months ago by felixxm

Patch needs improvement: set

comment:6 Changed 4 months ago by Ryan Cheley

Added example to 'time' as suggested by @felixxm here https://github.com/django/django/pull/12128

comment:7 Changed 4 months ago by Ryan Cheley

Added note to 'time' as suggested by @felixxm here ​https://github.com/django/django/pull/12128

comment:8 Changed 4 months ago by felixxm

Patch needs improvement: unset

comment:9 Changed 4 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In a1f14ee3:

Fixed #31006 -- Doc'd backslash escaping in date/time template filters.

comment:10 Changed 4 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In cd7f48e8:

[3.0.x] Fixed #31006 -- Doc'd backslash escaping in date/time template filters.

Backport of a1f14ee3e5a2160c2eef1dad58a1da11be4b1531 from master

comment:11 Changed 4 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In e8b09039:

[2.2.x] Fixed #31006 -- Doc'd backslash escaping in date/time template filters.

Backport of a1f14ee3e5a2160c2eef1dad58a1da11be4b1531 from master

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