Bug #68474 [Ver->Csd]: DateTime comparison fails

From: Date: Mon, 05 Apr 2021 15:55:37 +0000
Subject: Bug #68474 [Ver->Csd]: DateTime comparison fails
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233171@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68474&edit=1 ID: 68474 Updated by: derick@php.net Reported by: cwente at ip dot ulagos dot cl Summary: DateTime comparison fails -Status: Verified +Status: Closed Type: Bug Package: Date/time related Operating System: Debian Linux 7.7 PHP Version: 5.5.19 -Assigned To: +Assigned To: derick Block user comment: N Private report: N New Comment: Thank you for your bug report. This issue has already been fixed in the latest released version of PHP, which you can download at http://www.php.net/downloads.php This was fixed in PHP 7.0 already. Previous Comments: ------------------------------------------------------------------------ [2016-05-19 18:16:35] Rican7 at gmail dot com Related To: Bug #72243 ------------------------------------------------------------------------ [2015-04-19 23:15:44] cmb@php.net Apparently, the behavior changed with PHP 5.5.10: <http://3v4l.org/dTOrf#v5430>. It might be related to fixing bug #45528. ------------------------------------------------------------------------ [2015-02-02 05:46:40] dana dot desrosiers at gmail dot com The test description on Line 2 is not correct. Looks like it was copied from another test. It looks like the EXPECT section shows the current behavior, including an illustration of the workaround. I think its meant to show what should happen when the bug is fixed, right? I know this is modeled after the original bug reporter's example, but I think its more complicated than it needs to be to test the bug. Here's a more simple illustration: // Create two identical DateTime objects $a = new DateTime("2015-02-01 00:00:00", new DateTimeZone("PST")); $b = clone $a; // They should be equal (and they are) compare($a, $b); // Now change the timezone to EST. $b->setTimezone(new DateTimeZone("EST")); //The actual timestamp should not change (it does not in PHP 5.4) so $a should still be equal to $b, but it will say $a > $b. compare($a, $b); The workaround: $b->getTimestamp(); compare($a, $b); // it will now correctly report "$a == $b". Thanks for working on this. ------------------------------------------------------------------------ [2015-01-31 20:59:53] me at philsturgeon dot uk Can you let me know if this test script looks right? https://github.com/philsturgeon/php-src/compare/bug68474?expand=1#diff-2a05f4a70189b96241223c2ea214ffc9R1 I'll try and get it fixed up if you can help me confirm the expected result. ------------------------------------------------------------------------ [2015-01-31 02:37:15] dana dot desrosiers at gmail dot com I ran into this problem in PHP 5.6.3 as well. This is what I think is happening: The DateTime object has a timestamp property that is used to compare two DateTime objects using comparison operators (<, >, ==, etc.). When the setTimezone() method is called, the timezone property is set, but the internal timestamp is never updated, so comparisons may be wrong. Calling getTimestamp() or modify() after setTimezone() corrects the error. This bug does not exist in 5.3.27. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=68474 -- Edit this bug report at https://bugs.php.net/bug.php?id=68474&edit=1

« previous php.bugs (#233171) next »