|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #79903 datetime: new format "p", same as "P" but returning "Z" for UTC
Submitted: 2020-07-27 16:35 UTC Modified: 2020-08-03 08:47 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: mail at gh01 dot de Assigned: cmb (profile)
Status: Closed Package: Date/time related
PHP Version: Next Major Version OS:
Private report: No CVE-ID: None
 [2020-07-27 16:35 UTC] mail at gh01 dot de
ISO 8601 differentiates between local time (without time zone), UTC with letter "Z" and time offsets from UTC like "+02:00".

When formatting datetimes, it is sometimes desired to get the "Z" for UTC times and otherwise the offset.
But at the moment there are only the formatting chars "O" (for "+0200" etc.) and "P" (for "+02:00" etc.).

I suggest to add lower case "p" as another formatting char which behaves the same as upper case "P" but returns "Z" for UTC datetimes.

Test script:

$datetime = new DateTime('2020-07-26 20:00:00', new DateTimeZone('UTC'));
$datetime->format('Y-m-d\TH:i:sP'); // '2020-07-26T20:00:00+00:00'
$datetime->format('Y-m-d\TH:i:sp'); // '2020-07-26T20:00:00Z'

$datetime = new DateTime('2020-07-26 20:00:00', new DateTimeZone('Europe/London'));
$datetime->format('Y-m-d\TH:i:sP'); // '2020-07-26T20:00:00+00:00'
$datetime->format('Y-m-d\TH:i:sp'); // '2020-07-26T20:00:00+00:00'

$datetime = new DateTime('2020-07-26 20:00:00', new DateTimeZone('Europe/Berlin'));
$datetime->format('Y-m-d\TH:i:sP'); // '2020-07-26T20:00:00+02:00'
$datetime->format('Y-m-d\TH:i:sp'); // '2020-07-26T20:00:00+02:00'


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-27 17:05 UTC] mail at gh01 dot de
The following pull request has been associated:

Patch Name: datetime: new format "p", same as "P" but returning "Z" for UTC
On GitHub:
 [2020-07-30 11:08 UTC] samle at email dot tst
it's one thing that the bugtracker has no protection against assholes but accepting identical comments within the same second?
 [2020-08-02 00:58 UTC] antonino dot spampinato86 at gmail dot com
Characters in single quotes in the formats are case-insensitive ('t' could be t or T), characters in double quotes are case-sensitive ("T" is only T).
 [2020-08-02 01:40 UTC]
@antonino: That only applies to what is written in the Supported Formats pages themselves. The characters listed in the functions' documentation are case-sensitive.
 [2020-08-03 08:47 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Jan 18 08:01:26 2021 UTC