-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
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.[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[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
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