Bug #69378 [NEW]: Incorrect Result for DateTime::sub()

From: Date: Sun, 05 Apr 2015 14:47:10 +0000
Subject: Bug #69378 [NEW]: Incorrect Result for DateTime::sub()
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191836@lists.php.net to get a copy of this message
From: support at eggplantsd dot com Operating system: Debian Wheezy x64 PHP version: 5.4.39 Package: Date/time related Bug Type: Bug Bug description:Incorrect Result for DateTime::sub() Description: ------------ B - (B - A) == A SHOULD HOLD TRUE DOES HOLD TRUE USING UNIX TIMESTAMP MATH DOES NOT HOLD TRUE USING DateTime:sub() Test script: --------------- /* METHODOLOGY: B - (B - A) == A SHOULD HOLD TRUE DOES HOLD TRUE USING UNIX TIMESTAMP MATH DOES NOT HOLD TRUE USING DateTime:sub() */ $DF_MYSQL = 'Y-m-d H:i:s'; $dtB = DateTime::createFromFormat($DF_MYSQL, '2015-04-02 09:44:47'); $dtA = DateTime::createFromFormat($DF_MYSQL, '2014-02-16 02:00:00'); // DateInterval: B-A $diDiff = $dtA->diff($dtB); // Unix Timestamp: B-A $tsDiff = $dtB->getTimestamp() - $dtA->getTimestamp(); // REPORT DIFFERENCES /* NOTE: DIFFERENCE B-A IS $y => 1 $m => 1 $d => 17 $h => 7 $i => 44 $s => 47 */ print_r($diDiff); // Unix Timestamp: CALCULATE A FROM (B - DIFFERENCE) AND REPORT // NOTE: CORRECT RESULT, SAME AS $dtA: 2014-02-16 02:00:00 $tsShift = $dtB->getTimestamp() - $tsDiff; $dtOut = new DateTime(); $dtOut->setTimestamp($tsShift); print_r($dtOut); // DateInterval: CALCULATE A FROM (B - DIFFERENCE) AND REPORT // NOTE: INCORRECT RESULT, DIFFERENT FROM $dtA: 2014-02-13 02:00:00 $dtB->sub($diDiff); print_r($dtB); Expected result: ---------------- SEE SCRIPT COMMENTS Actual result: -------------- SEE SCRIPT COMMENTS -- Edit bug report at https://bugs.php.net/bug.php?id=69378&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=69378&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=69378&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=69378&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=69378&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=69378&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=69378&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=69378&r=needscript Try newer version: https://bugs.php.net/fix.php?id=69378&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=69378&r=support Expected behavior: https://bugs.php.net/fix.php?id=69378&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=69378&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=69378&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=69378&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69378&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=69378&r=dst IIS Stability: https://bugs.php.net/fix.php?id=69378&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=69378&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=69378&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=69378&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=69378&r=mysqlcfg

« previous php.bugs (#191836) next »