[php-src] Issue #8475: DateTimeImmutable->diff fails to understand months in Europe/Paris timezone

From: Date: Sun, 01 May 2022 18:14:01 +0000
Subject: [php-src] Issue #8475: DateTimeImmutable->diff fails to understand months in Europe/Paris timezone
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-241358@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8475 Author: atomikaya ### Description The following code: ```php <?php date_default_timezone_set('Europe/Paris'); $april = new \DateTimeImmutable('2022-02-01T00:00:00'); $may = new \DateTimeImmutable('2022-03-01T00:00:00'); echo $april->format(\DateTimeInterface::ATOM) . PHP_EOL; echo $may->format(\DateTimeInterface::ATOM) . PHP_EOL; var_dump($april->diff($may)); ``` Resulted in this output: ``` 2022-02-01T00:00:00+01:00 2022-03-01T00:00:00+01:00 object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(0) ["d"]=> int(28) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(28) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } ``` But I expected this output instead: ``` 2022-02-01T00:00:00+01:00 2022-03-01T00:00:00+01:00 object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(1) ["d"]=> int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0) ["f"]=> float(0) ["weekday"]=> int(0) ["weekday_behavior"]=> int(0) ["first_last_day_of"]=> int(0) ["invert"]=> int(0) ["days"]=> int(0) ["special_type"]=> int(0) ["special_amount"]=> int(0) ["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) } ``` This is not a special case for February ; some months, like April, also sum up to 30 days but not a full month (just in case, April 31st is not a thing). To get a full month and zero spare days, I have to set the interval between April 1st and May 2nd. By simply setting the timezone to UTC, the behavior disappears. ### PHP Version 7.2.24, 8.0.18 ### Operating System _No response_

« previous php.bugs (#241358) next »