|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2021-05-23 09:58 UTC] php-bugs at allenjb dot me dot uk
[2021-08-08 11:49 UTC] derick@php.net
-Status: Open
+Status: Not a bug
[2021-08-08 11:49 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 01:00:02 2025 UTC |
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