[Django] #34387: DateFormat.P() does not follow PHP's date string format

12 views
Skip to first unread message

Django

unread,
Mar 5, 2023, 4:24:03 AM3/5/23
to django-...@googlegroups.com
#34387: DateFormat.P() does not follow PHP's date string format
--------------------------------------+------------------------
Reporter: nullwaves | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
--------------------------------------+------------------------
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"

--
Ticket URL: <https://code.djangoproject.com/ticket/34387>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 5, 2023, 7:56:36 AM3/5/23
to django-...@googlegroups.com
#34387: DateFormat.P() does not follow PHP's date string format
---------------------------+--------------------------------------
Reporter: null | Owner: nobody
Type: Bug | Status: closed
Component: Utilities | Version: 3.2
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
---------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix


Comment:

Thanks for this patch, however it works as
[https://docs.djangoproject.com/en/stable/ref/templates/builtins/#date
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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34387#comment:1>

Django

unread,
Mar 5, 2023, 5:47:57 PM3/5/23
to django-...@googlegroups.com
#34387: DateFormat.P() does not follow PHP's date string format
-------------------------------+--------------------------------------
Reporter: null | Owner: nobody
Type: Uncategorized | Status: new
Component: Utilities | Version: 4.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by null):

* status: closed => new
* type: Bug => Uncategorized
* version: 3.2 => 4.2
* resolution: wontfix =>


Comment:

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
>>>
"""
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34387#comment:2>

Django

unread,
Mar 5, 2023, 10:25:25 PM3/5/23
to django-...@googlegroups.com
#34387: DateFormat.P() does not follow PHP's date string format
-------------------------------+------------------------------------------
Reporter: null | Owner: ayushbisht2001
Type: Uncategorized | Status: assigned

Component: Utilities | Version: 4.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------------
Changes (by ayushbisht2001):

* owner: nobody => ayushbisht2001
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/34387#comment:3>

Django

unread,
Mar 5, 2023, 11:21:10 PM3/5/23
to django-...@googlegroups.com
#34387: DateFormat.P() does not follow PHP's date string format
-------------------------------+---------------------------------------
Reporter: null | Owner: Ayush Bisht
Type: Uncategorized | Status: closed
Component: Utilities | Version: 4.2
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+---------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => wontfix


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/34387#comment:4>

Reply all
Reply to author
Forward
0 new messages