Req #79903 [Com]: datetime: new format "p", same as "P" but returning "Z" for UTC
| From: | sample at email dot tst | Date: | Thu, 30 Jul 2020 10:30:44 +0000 |
| Subject: | Req #79903 [Com]: datetime: new format "p", same as "P" but returning "Z" for UTC | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-228301@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79903&edit=1
ID: 79903
Comment by: sample at email dot tst
Reported by: mail at gh01 dot de
Summary: datetime: new format "p", same as "P" but returning
"Z" for UTC
Status: Open
Type: Feature/Change Request
Package: Date/time related
PHP Version: Next Major Version
Block user comment: N
Private report: N
New Comment:
555
Previous Comments:
------------------------------------------------------------------------
[2020-07-30 10:30:42] sample at email dot tst
555
------------------------------------------------------------------------
[2020-07-30 10:30:37] sample at email dot tst
555
------------------------------------------------------------------------
[2020-07-30 10:30:36] sample at email dot tst
555
------------------------------------------------------------------------
[2020-07-27 17:05:43] 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: https://github.com/php/php-src/pull/5896
Patch: https://github.com/php/php-src/pull/5896.patch
------------------------------------------------------------------------
[2020-07-27 16:35:41] mail at gh01 dot de
Description:
------------
ISO 8601 differentiates between local time (without time zone), UTC with letter "Z" and
time offsets from UTC like "+02:00".
https://en.wikipedia.org/wiki/ISO_8601#Time_zone_designators
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.
https://github.com/php/php-src/pull/5896
Test script:
---------------
<?php
$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'
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79903&edit=1