Bug #76182 [NEW]: DateTime::diff does not respect timezone offset

From: Date: Tue, 03 Apr 2018 23:58:19 +0000
Subject: Bug #76182 [NEW]: DateTime::diff does not respect timezone offset
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-214589@lists.php.net to get a copy of this message
From: zerkms at zerkms dot ru Operating system: Linux/Any PHP version: 7.2.4 Package: Date/time related Bug Type: Bug Bug description:DateTime::diff does not respect timezone offset Description: ------------ If you subtract timezones from the different sides of the standard/dst time boundary - the result is wrong. Test script: --------------- <?php $dt = new \DateTime('2018-04-01 03:10:00', new \DateTimeZone('Pacific/Auckland')); $dt2 = clone $dt; $dt2->sub(new \DateInterval('PT2H')); var_dump($dt > $dt2, $dt->format(\DateTime::RFC3339), $dt2->format(\DateTime::RFC3339), $dt->diff($dt2)->format('%h')); Expected result: ---------------- bool(true) string(25) "2018-04-01T03:10:00+12:00" string(25) "2018-04-01T02:10:00+13:00" string(1) "2" Actual result: -------------- bool(true) string(25) "2018-04-01T03:10:00+12:00" string(25) "2018-04-01T02:10:00+13:00" string(1) "1" -- Edit bug report at https://bugs.php.net/bug.php?id=76182&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76182&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76182&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76182&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=76182&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=76182&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=76182&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=76182&r=needscript Try newer version: https://bugs.php.net/fix.php?id=76182&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=76182&r=support Expected behavior: https://bugs.php.net/fix.php?id=76182&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=76182&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=76182&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=76182&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76182&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=76182&r=dst IIS Stability: https://bugs.php.net/fix.php?id=76182&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=76182&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=76182&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=76182&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=76182&r=mysqlcfg

« previous php.bugs (#214589) next »