Closed
Description
Description
The following code: https://3v4l.org/EMU1K
<?php
$dt = new DateTime('2015-01-01 00:00:00+00:00');
var_dump($dt->format('c'));
var_dump($dt->modify('+1 s')->format('c'));
$dt = new DateTimeImmutable('2015-01-01 00:00:00+00:00');
var_dump($dt->format('c'));
var_dump($dt->modify('+1 s')->format('c'));
Resulted in this output:
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+01:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+01:00"
But I expected this output instead:
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
string(25) "2015-01-01T00:00:00+00:00"
As you can see it's modifying the time zone offset from +00:00
to +01:00
instead of doing nothing as s
is not a valid unit according to https://www.php.net/manual/en/datetime.formats.relative.php.
It's interesting here because s
is a common mistake as abbr. of second
& sec
where also ms
and µs
would be valid (which is another topic) but there is also no documented way of modifying the time zone using modify
and in this particular case it's effectively moving backward instead of forward.
PHP Version
PHP 8.1.15 / PHP 8.2.2
Operating System
Linux