[php-src] Issue #7959: DateTime::setTimestamp producing a DateTime that gives incorrect results during DST switch period

From: Date: Mon, 17 Jan 2022 15:59:21 +0000
Subject: [php-src] Issue #7959: DateTime::setTimestamp producing a DateTime that gives incorrect results during DST switch period
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239072@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/7959 Author: danhowardms ### Description The following code: ```php <?php date_default_timezone_set('Europe/London'); $ts = 1635641999; $t = (new \DateTime())->setTimestamp($ts); echo $t->format('r'), "\n"; echo $t->getTimestamp(), "\n"; echo ($ts === $t->getTimestamp() ? 'correct' : 'incorrect'), "\n\n"; $ts++; $t = (new \DateTime())->setTimestamp($ts); echo $t->format('r'), "\n"; echo $t->getTimestamp(), "\n"; echo ($ts === $t->getTimestamp() ? 'correct' : 'incorrect'), "\n\n"; ``` Resulted in this output: ``` Sun, 31 Oct 2021 01:59:59 +0000 1635645599 incorrect Sun, 31 Oct 2021 01:00:00 +0000 1635642000 correct ``` But I expected this output instead: ``` Sun, 31 Oct 2021 01:59:59 +0100 1635641999 incorrect Sun, 31 Oct 2021 01:00:00 +0000 1635642000 correct ``` We get the incorrect timestamp during the daylight saving time switch for Europe/London. At @1635641999 the time in Europe/London is 01:59:59, but at that time we are still in BST (GMT+0100), but the GMT difference reported by the DateTime format() function is incorrectly showing +0000. I would guess that the getTimestamp() function is giving a value that is incorrect by 3600 seconds for the same reason. ### PHP Version PHP 8.1.1 ### Operating System _No response_

« previous php.bugs (#239072) next »