Bug #81074 [NEW]: DateTime::setTime causes unexpected offset change

From: Date: Sun, 23 May 2021 09:57:30 +0000
Subject: Bug #81074 [NEW]: DateTime::setTime causes unexpected offset change
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233995@lists.php.net to get a copy of this message
From: php-bugs at allenjb dot me dot uk Operating system: PHP version: 8.0.6 Package: Date/time related Bug Type: Bug Bug description:DateTime::setTime causes unexpected offset change 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 bug report at https://bugs.php.net/bug.php?id=81074&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=81074&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=81074&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=81074&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=81074&r=needscript Try newer version: https://bugs.php.net/fix.php?id=81074&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=81074&r=support Expected behavior: https://bugs.php.net/fix.php?id=81074&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=81074&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=81074&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=81074&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=81074&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=81074&r=dst IIS Stability: https://bugs.php.net/fix.php?id=81074&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=81074&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=81074&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=81074&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=81074&r=mysqlcfg

« previous php.bugs (#233995) next »