Bug #80664 [NEW]: DateTime::add() behaves incorrectly at DST transition

From: Date: Sun, 24 Jan 2021 21:53:45 +0000
Subject: Bug #80664 [NEW]: DateTime::add() behaves incorrectly at DST transition
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-231741@lists.php.net to get a copy of this message
From: AaronB at landproDATA dot com Operating system: Irrelevant PHP version: 7.3.26 Package: Date/time related Bug Type: Bug Bug description:DateTime::add() behaves incorrectly at DST transition Description: ------------ DateTime::add() behaves incorrectly when adding times to a DateTime representing a point during the hour that is repeated during a transition from daylight savings time to standard time. This problem seems to arise only in cases where the associated DateTimeZone has been defined using a geographical label like 'America/Boise'. One thing that is especially surprising in these cases is that using DateTime::add() to add an hour to a time can cause the description of the timezone that is reported by the 'T' format option to change in such a way that the operation appears to have succeed as intended while the call to DateTime::add() actually leaves the underlying Unix timestamp entirely unchanged. What this means is that there is a bug in DateTime::format(), as well as in DateTime::add(). I have verified that this problem occurs in PHP 7.3.21 and PHP 7.4.0. Test script: --------------- $dt = new DateTime('@1604215800'); $dt->setTimezone(new DateTimeZone('America/Boise')); echo "{$dt->format('Y-m-d H:i:s T')} | {$dt->getTimestamp()}\r\n"; $dt->add(new DateInterval('PT1H')); echo "{$dt->format('Y-m-d H:i:s T')} | {$dt->getTimestamp()}\r\n"; $dt->add(new DateInterval('PT1H')); echo "{$dt->format('Y-m-d H:i:s T')} | {$dt->getTimestamp()}\r\n"; $dt->add(new DateInterval('PT1M')); echo "{$dt->format('Y-m-d H:i:s T')} | {$dt->getTimestamp()}\r\n"; Expected result: ---------------- 2020-11-01 01:30:00 MDT | 1604215800 2020-11-01 01:30:00 MST | 1604219400 2020-11-01 02:30:00 MST | 1604223000 2020-11-01 02:31:00 MST | 1604223060 Actual result: -------------- 2020-11-01 01:30:00 MDT | 1604215800 2020-11-01 01:30:00 MST | 1604215800 2020-11-01 01:30:00 MST | 1604215800 2020-11-01 01:31:00 MDT | 1604215860 -- Edit bug report at https://bugs.php.net/bug.php?id=80664&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80664&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80664&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80664&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80664&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80664&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80664&r=support Expected behavior: https://bugs.php.net/fix.php?id=80664&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80664&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80664&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80664&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80664&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80664&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80664&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80664&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80664&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80664&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80664&r=mysqlcfg

« previous php.bugs (#231741) next »