Bug #75167 [Opn->Csd]: DateTime::add does only care about backward DST transition, not forward

From: Date: Tue, 06 Apr 2021 19:55:01 +0000
Subject: Bug #75167 [Opn->Csd]: DateTime::add does only care about backward DST transition, not forward
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233260@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75167&edit=1 ID: 75167 Updated by: derick@php.net Reported by: knutoh at gmail dot com Summary: DateTime::add does only care about backward DST transition, not forward -Status: Open +Status: Closed Type: Bug Package: Date/time related Operating System: irrelevant PHP Version: 7.1.9 -Assigned To: +Assigned To: derick Block user comment: N Private report: N New Comment: The fix for this bug has been committed. If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test. Thank you for the report, and for helping us make PHP better. Fixed for PHP 8.1. Previous Comments: ------------------------------------------------------------------------ [2017-09-07 12:06:16] knutoh at gmail dot com Note that this is _not_ related to all the issues on the DateTime::modify function. https://bugs.php.net/bug.php?id=74274 This bug is really simple to fix (just some lines in interval.c that needs to be copied) Most of those others are more complex. ------------------------------------------------------------------------ [2017-09-07 11:42:15] knutoh at gmail dot com Description: ------------ This change in this commit: http://git.php.net/?p=php-src.git;a=blobdiff;f=ext/date/lib/interval.c;h=dce62f3a2803db69af026105f8c862806c512bcf;hp=7fa1fc5c13f24c05ddae53b9fa952bca344ff318;hb=582f6e529e843b412d582023bf0270e47b1aa468;hpb=5d0c526199add0e4f054a57db29d882c8ad89a23 fixes so that DateTime::sub and DateTime::add handles DST transitions correctly. But derickr probably just forgot to handle forward DST transition in the DateTime::add function. Test script: --------------- $tz = new DateTimeZone('Europe/London'); // A timezone that has DST $five_hours_interval = new DateInterval('PT5H'); $date = new DateTime("2014-3-30 00:00:00", $tz); // Add five hours and subtract 5 hours. The $newDate should then equal the date. $five_hours_later = (clone $date)->add($five_hours_interval); $newDate = (clone $five_hours_later)->sub($five_hours_interval); echo $date->format('c') . "\n"; echo $newDate->format('c'); Expected result: ---------------- 2014-03-30T00:00:00+00:00 2014-03-30T00:00:00+00:00 Actual result: -------------- 2014-03-30T00:00:00+00:00 2014-03-29T23:00:00+00:00 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75167&edit=1

« previous php.bugs (#233260) next »