diff --git a/NEWS b/NEWS index 591655bd107d0..c46839c5243f3 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ PHP NEWS . Fixed bug #79108 (Referencing argument in a function makes it a reference in the stack trace). (Nikita) +- Date: + . Implemented FR #79903 (datetime: new format "p", same as "P" but returning + "Z" for UTC). (gharlan) + - JIT: . Fixed bug #79864 (JIT segfault in Symfony OptionsResolver). (Dmitry) diff --git a/ext/date/php_date.c b/ext/date/php_date.c index 46d50e283718f..67b1bb2d3892d 100644 --- a/ext/date/php_date.c +++ b/ext/date/php_date.c @@ -711,6 +711,12 @@ static zend_string *date_format(const char *format, size_t format_len, timelib_t /* timezone */ 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 'O': length = slprintf(buffer, sizeof(buffer), "%c%02d%s%02d", localtime ? ((offset->offset < 0) ? '-' : '+') : '+', diff --git a/ext/date/tests/date_format_timezone.phpt b/ext/date/tests/date_format_timezone.phpt new file mode 100644 index 0000000000000..ea4575e4ce395 --- /dev/null +++ b/ext/date/tests/date_format_timezone.phpt @@ -0,0 +1,43 @@ +--TEST-- +Test date_format() function : timezone offset +--FILE-- + +--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"