[php-src] Issue #10005: Wrong with prev February
| From: | hormus | Date: | Sat, 26 Nov 2022 19:14:47 +0000 |
| Subject: | [php-src] Issue #10005: Wrong with prev February | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242950@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10005
Author: hormus
### Description
The following code (from php >= 5.3:
```php
<?php
$utc = new \DateTimeZone('UTC');
$london = new \DateTimeZone('Europe/London');
$test1 = new \DateTime('2018-01-31 00:00:00', $utc);
$test2 = new \DateTime('2018-03-30 23:00:00', $utc);
//$dateDiff = $test2->diff($test1); // true absolute Should the interval be forced to be positive
$dateDiff = $test1->diff($test2);
$bugs = array('y' => &$dateDiff->y, 'm' => &$dateDiff->m,
'd' => &$dateDiff->d, 'h' => &$dateDiff->h,
'invert' => &$dateDiff->invert, 'days' => &$dateDiff->days);
$test3 = new \DateTime('+2 month ' . $test1->format('Y-m-d\\TH:i:s\\Z'));
$test4 = $test2->sub($dateDiff);
var_dump($test4->format('Y-m-d H:i:s +00:00'), $bugs);
?>
```
Resulted in this output:
```code
string(26) "2018-02-03 00:00:00 +00:00"
array(6) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(27)
["h"]=>
int(23)
["invert"]=>
int(0)
["days"]=>
int(58)
}
```
But I expected this output instead:
```code
string(26) "2018-01-31 00:00:00 +00:00"
array(6) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(27)
["h"]=>
int(23)
["invert"]=>
int(0)
["days"]=>
int(58)
}
```
### PHP Version
Any
### Operating System
_No response_