[php-src] Issue #14593: DateTime: Z not recognised as UTC (+00:00)

From: Date: Tue, 18 Jun 2024 05:52:54 +0000
Subject: [php-src] Issue #14593: DateTime: Z not recognised as UTC (+00:00)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-247109@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/14593 Author: marc-mabe ### Description The character Z (and to my knowladge z as well) is known in ISO8601 to represent the UTC timezone aka +00:00 but DateTime[Immutable] does not detect this as UTC or +00:00. Instead the latter Z is used as timezone name. Interestingly DatePeriod::createFromISO8601String does recognize it as +00:00 correctly. Additionally there is a note in wikipedia: > The Z suffix in the ISO 8601 time representation is sometimes referred to as "Zulu > time" or "Zulu meridian" because the same letter is used to designate the [Zulu time > zone](https://en.wikipedia.org/wiki/List_of_military_time_zones).[[30]](https://en.wikipedia.org/wiki/ISO_8601#cite_note-30) > However the ACP 121 standard that defines the list of military time zones makes no mention of UTC > and derives the "Zulu time" from the [Greenwich Mean > Time](https://en.wikipedia.org/wiki/Greenwich_Mean_Time)[[31]](https://en.wikipedia.org/wiki/ISO_8601#cite_note-ACP_121_I-31) > which was formerly used as the international civil time standard. ... ... which makes me wonder if the recognized timezone Z is actually Zulu time or something unknown that falls back to UTC? The following code: https://3v4l.org/u2fmJ#v8.3.8 ```php <?php date_default_timezone_set('Europe/Berlin'); $dt = new DateTimeImmutable('2008-03-01T13:00:00Z'); var_dump($dt, $dt->getOffset(), $dt->modify('+6month'), $dt->modify('+6month')->getOffset()); var_dump(DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:sT', '2008-03-01T13:00:00Z')); var_dump(DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:sO', '2008-03-01T13:00:00Z')); var_dump(DateTimeImmutable::createFromFormat('Y-m-d\\TH:i:sP', '2008-03-01T13:00:00Z')); $dp = DatePeriod::createFromISO8601String('R1/2008-03-01T13:00:00Z/P1Y2M10DT2H30M'); foreach ($dp as $d) { var_dump($d); } ``` Resulted in this output: ``` object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(1) "Z" } int(0) object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-09-01 13:00:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(1) "Z" } int(0) object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(1) "Z" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(1) "Z" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(2) ["timezone"]=> string(1) "Z" } object(DateTimeImmutable)#6 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTimeImmutable)#8 (3) { ["date"]=> string(26) "2009-05-11 15:30:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ``` But I expected this output instead: ``` object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(1) "+00:00" } int(0) object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-09-01 13:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(1) "+00:00" } int(0) object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(1) "+00:00" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(1) "+00:00" } object(DateTimeImmutable)#2 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(1) "+00:00" } object(DateTimeImmutable)#6 (3) { ["date"]=> string(26) "2008-03-01 13:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } object(DateTimeImmutable)#8 (3) { ["date"]=> string(26) "2009-05-11 15:30:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } ``` ### PHP Version PHP 8.3 ### Operating System _No response_

« previous php.bugs (#247109) next »