Bug #81074 [Com]: DateTime::setTime causes unexpected offset change
Edit report at https://bugs.php.net/bug.php?id=81074&edit=1
ID: 81074
Comment by: php-bugs at allenjb dot me dot uk
Reported by: php-bugs at allenjb dot me dot uk
Summary: DateTime::setTime causes unexpected offset change
Status: Open
Type: Bug
Package: Date/time related
PHP Version: 8.0.6
Block user comment: N
Private report: N
New Comment:
Forgot to mention: I tested this on current master this morning and the issue still occurs there.
Previous Comments:
------------------------------------------------------------------------
[2021-05-23 09:57:30] php-bugs at allenjb dot me dot uk
Description:
------------
When using ->setTime() on a DateTime object, the offset may be changed even if the new time is
valid in the existing offset.
(Aside: This bug also reveals that with the current API it's actually impossible to use
->setTime() to set some valid time values)
Test script:
---------------
<?php
$tzUK = new DateTimeZone("Europe/London");
$tzUtc = new DateTimeZone("UTC");
$dt = DateTime::createFromFormat("!Y-m-d H:i:s", "2020-10-25 00:05:00", $tzUtc);
$dt = DateTime::createFromFormat('U', $dt->format('U'));
print $dt->format(DateTime::RFC3339 ." e") ."\n";
$dt->setTimeZone($tzUK);
print $dt->format(DateTime::RFC3339 ." e") ."\n";
$dt->setTime((int) $dt->format('H'), (int) $dt->format('i'), 0);
print $dt->format(DateTime::RFC3339 ." e") ."\n";
Expected result:
----------------
2020-10-25T00:05:00+00:00 +00:00
2020-10-25T01:05:00+01:00 Europe/London
2020-10-25T01:05:00+01:00 Europe/London
Actual result:
--------------
2020-10-25T00:05:00+00:00 +00:00
2020-10-25T01:05:00+01:00 Europe/London
2020-10-25T01:05:00+00:00 Europe/London
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=81074&edit=1
Thread (3 messages)