#34387 closed Uncategorized (wontfix)

DateFormat.P() does not follow PHP's date string format

Reported by: null Owned by: Ayush Bisht
Component: Utilities Version: 4.2
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

PHP's documentation defines the P character as follows:

"P Difference to Greenwich time (GMT) with colon between hours and minutes Example: +02:00"

However in django, P() appears to be implemented as
"Time, in 12-hour hours, minutes and 'a.m.'/'p.m.', with minutes left off

if they're zero and the strings 'midnight' and 'noon' if appropriate.
Examples: '1 a.m.', '1:30 p.m.', 'midnight', 'noon', '12:30 p.m.'
Proprietary extension."

For example:

DateFormat(self.created_on).format("F jS Y, h:ia P")

returns "March 5th 2023, 08:44a.m. 8:44 a.m." when it should return "March 5th 2023, 08:44a.m. -05:00"

Change History (4)

comment:1 by Mariusz Felisiak, 21 months ago

Resolution: wontfix
Status: newclosed

Thanks for this patch, however it works as documented:

"Uses a similar format to PHP’s date() function with some differences."
"Time, in 12-hour hours, minutes and ‘a.m.’/’p.m.’, with minutes left off if they’re zero and the special-case strings ‘midnight’ and ‘noon’ if appropriate. Proprietary extension."

We will not make a backward incompatible change to follow the PHP implementation.

comment:2 by null, 21 months ago

Resolution: wontfix
Status: closednew
Type: BugUncategorized
Version: 3.24.2

In that case the inline documentation is incorrect and should be updated as in djang.utils.dateformat it still, as of 4.2, reads:

"""
PHP date() style date formatting
See http://www.php.net/date for format strings

Usage:
>>> import datetime
>>> d = datetime.datetime.now()
>>> df = DateFormat(d)
>>> print(df.format('jS F Y H:i'))
7th October 2003 11:39
>>>
"""

comment:3 by Ayush Bisht, 21 months ago

Owner: changed from nobody to Ayush Bisht
Status: newassigned

comment:4 by Mariusz Felisiak, 21 months ago

Resolution: wontfix
Status: assignedclosed

I appreciate you'd like to reopen the ticket, but I don't see anything wrong in this docstring. We could remove "See http://www.php.net/date for format strings" as there is no need to check PHP docs for format strings but such a tiny cleanup doesn't require a ticket.

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