mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
datetime: new format "p", same as "P" but returning "Z" for UTC
This commit is contained in:
parent
bb8b95be63
commit
a6e3ce4fd6
4 changed files with 53 additions and 0 deletions
2
NEWS
2
NEWS
|
@ -13,6 +13,8 @@ PHP NEWS
|
||||||
- Date:
|
- Date:
|
||||||
. Fixed bug #60302 (DateTime::createFromFormat should new static(), not new
|
. Fixed bug #60302 (DateTime::createFromFormat should new static(), not new
|
||||||
self()). (Derick)
|
self()). (Derick)
|
||||||
|
. Implemented FR #79903 (datetime: new format "p", same as "P" but returning
|
||||||
|
"Z" for UTC). (gharlan)
|
||||||
|
|
||||||
- JIT:
|
- JIT:
|
||||||
. Fixed bug #79864 (JIT segfault in Symfony OptionsResolver). (Dmitry)
|
. Fixed bug #79864 (JIT segfault in Symfony OptionsResolver). (Dmitry)
|
||||||
|
|
|
@ -683,6 +683,8 @@ PHP 8.0 UPGRADE NOTES
|
||||||
- Date:
|
- Date:
|
||||||
. Added DateTime::createFromInterface() and
|
. Added DateTime::createFromInterface() and
|
||||||
DateTimeImmutable::createFromInterface().
|
DateTimeImmutable::createFromInterface().
|
||||||
|
. Added the DateTime format specifier "p" which is the same as "P" but
|
||||||
|
returning "Z" for UTC.
|
||||||
|
|
||||||
- Dom:
|
- Dom:
|
||||||
. Introduce DOMParentNode and DOMChildNode with new traversal and
|
. Introduce DOMParentNode and DOMChildNode with new traversal and
|
||||||
|
|
|
@ -711,6 +711,12 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t
|
||||||
|
|
||||||
/* timezone */
|
/* timezone */
|
||||||
case 'I': length = slprintf(buffer, sizeof(buffer), "%d", localtime ? offset->is_dst : 0); break;
|
case 'I': length = slprintf(buffer, sizeof(buffer), "%d", localtime ? offset->is_dst : 0); break;
|
||||||
|
case 'p':
|
||||||
|
if (!localtime || strcmp(offset->abbr, "UTC") == 0 || strcmp(offset->abbr, "Z") == 0) {
|
||||||
|
length = slprintf(buffer, sizeof(buffer), "%s", "Z");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
/* break intentionally missing */
|
||||||
case 'P': rfc_colon = 1; /* break intentionally missing */
|
case 'P': rfc_colon = 1; /* break intentionally missing */
|
||||||
case 'O': length = slprintf(buffer, sizeof(buffer), "%c%02d%s%02d",
|
case 'O': length = slprintf(buffer, sizeof(buffer), "%c%02d%s%02d",
|
||||||
localtime ? ((offset->offset < 0) ? '-' : '+') : '+',
|
localtime ? ((offset->offset < 0) ? '-' : '+') : '+',
|
||||||
|
|
43
ext/date/tests/date_format_timezone.phpt
Normal file
43
ext/date/tests/date_format_timezone.phpt
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
--TEST--
|
||||||
|
Test date_format() function : timezone offset
|
||||||
|
--FILE--
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$tz = array("UTC", "Europe/London", "Europe/Berlin", "America/Chicago");
|
||||||
|
|
||||||
|
foreach ($tz as $zone) {
|
||||||
|
echo $zone, "\n";
|
||||||
|
date_default_timezone_set($zone);
|
||||||
|
|
||||||
|
$date = date_create("2020-03-10 22:30:41");
|
||||||
|
|
||||||
|
var_dump( date_format($date, "O") );
|
||||||
|
var_dump( date_format($date, "P") );
|
||||||
|
var_dump( date_format($date, "p") );
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Z\n";
|
||||||
|
$date = date_create("2020-03-10 22:30:41Z");
|
||||||
|
|
||||||
|
var_dump( date_format($date, "p") );
|
||||||
|
|
||||||
|
?>
|
||||||
|
--EXPECT--
|
||||||
|
UTC
|
||||||
|
string(5) "+0000"
|
||||||
|
string(6) "+00:00"
|
||||||
|
string(1) "Z"
|
||||||
|
Europe/London
|
||||||
|
string(5) "+0000"
|
||||||
|
string(6) "+00:00"
|
||||||
|
string(6) "+00:00"
|
||||||
|
Europe/Berlin
|
||||||
|
string(5) "+0100"
|
||||||
|
string(6) "+01:00"
|
||||||
|
string(6) "+01:00"
|
||||||
|
America/Chicago
|
||||||
|
string(5) "-0500"
|
||||||
|
string(6) "-05:00"
|
||||||
|
string(6) "-05:00"
|
||||||
|
Z
|
||||||
|
string(1) "Z"
|
Loading…
Add table
Add a link
Reference in a new issue