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

From: Date: Tue, 14 Apr 2015 07:06:52 +0000
Subject: Bug #69378 [Com]: Incorrect Result for DateTime::sub()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192032@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69378&edit=1 ID: 69378 Comment by: andreas at heigl dot org Reported by: support at eggplantsd dot com Summary: Incorrect Result for DateTime::sub() Status: Open Type: Bug Package: Date/time related Operating System: Debian Wheezy x64 PHP Version: 5.4.39 Block user comment: N Private report: N New Comment: The change seems to have been introduces in PHP5.3.3 as can be seen in http://3v4l.org/mUeRk. Previous Comments: ------------------------------------------------------------------------ [2015-04-05 14:47:09] support at eggplantsd dot com 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 this bug report at https://bugs.php.net/bug.php?id=69378&edit=1

« previous php.bugs (#192032) next »