[php-src] Issue #15880: DateTimeImmutable (and DateTime) Modify does not respect Daylight Saving Time shifts
| From: | karptonite | Date: | Fri, 13 Sep 2024 19:31:54 +0000 |
| Subject: | [php-src] Issue #15880: DateTimeImmutable (and DateTime) Modify does not respect Daylight Saving Time shifts | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247780@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15880
Author: karptonite
### Description
The following code:
```php
<?php
date_default_timezone_set("America/Chicago");
$startDate = new DateTimeImmutable( "2024-11-01" );
var_dump( $startDate );
$endDate = $startDate->modify( '+72 hour' );
var_dump($endDate);
$otherEndDate = $startDate->add( new DateInterval( 'PT72H' ) );
var_dump( $otherEndDate );
```
Resulted in this output:
```
object(DateTimeImmutable)#1 (3) {
["date"]=>
string(26) "2024-11-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "America/Chicago"
}
object(DateTimeImmutable)#2 (3) {
["date"]=>
string(26) "2024-11-04 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "America/Chicago"
}
object(DateTimeImmutable)#4 (3) {
["date"]=>
string(26) "2024-11-03 23:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "America/Chicago"
}
```
But I expected this output instead:
```
object(DateTimeImmutable)#1 (3) {
["date"]=>
string(26) "2024-11-01 00:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "America/Chicago"
}
object(DateTimeImmutable)#4 (3) {
["date"]=>
string(26) "2024-11-03 23:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "America/Chicago"
}
object(DateTimeImmutable)#4 (3) {
["date"]=>
string(26) "2024-11-03 23:00:00.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(15) "America/Chicago"
}
```
Note that the from 11-1 to 11-4, Daylight Saving time ends. If you change the time by adding a
DateInterval, it gets it right, but it gets it wrong with modify.
### PHP Version
PHP 8.3
### Operating System
_No response_