Steps to replicate the issue (include links if applicable):
- Run php8.2 tests
What happens?:
Using PHP 8.2.10 PHPUnit 9.5.28 by Sebastian Bergmann and contributors. [...] There were 10 failures: 1) TimeAdjustTest::testUserAdjust with data set "Literal int -2 (technically undocumented)" ('20221015120000', -2, '20221015100000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015100000' +'20221015140000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 2) TimeAdjustTest::testUserAdjust with data set "Literal -5" ('20221015120000', '-5', '20221015070000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015070000' +'20221015170000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 3) TimeAdjustTest::testUserAdjust with data set "Literal -06:00" ('20221015120000', '-06:00', '20221015060000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015060000' +'20221015180000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 4) TimeAdjustTest::testUserAdjust with data set "Full format -06:00" ('20221015120000', 'Offset|-360', '20221015060000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015060000' +'20221015180000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 5) TimeAdjustTest::testUserAdjust with data set "Literal -06:45" ('20221015120000', '-06:45', '20221015051500') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015051500' +'20221015184500' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 6) TimeAdjustTest::testUserAdjust with data set "Full format -06:45" ('20221015120000', 'Offset|-405', '20221015051500') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015051500' +'20221015184500' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 7) TimeAdjustTest::testUserAdjust with data set "Literal -12:00" ('20221015120000', '-12:00', '20221015000000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015000000' +'20221016000000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 8) TimeAdjustTest::testUserAdjust with data set "Full format -12:00" ('20221015120000', 'Offset|-720', '20221015000000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015000000' +'20221016000000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 9) TimeAdjustTest::testUserAdjust with data set "Literal -13:00, capped at -12" ('20221015120000', '-13:00', '20221015000000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015000000' +'20221016000000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16 10) TimeAdjustTest::testUserAdjust with data set "Full format -13:00, capped at -12" ('20221015120000', 'Offset|-780', '20221015000000') Failed asserting that two strings are identical. --- Expected +++ Actual @@ @@ -'20221015000000' +'20221016000000' /workspace/src/tests/phpunit/includes/language/TimeAdjustTest.php:16
What should have happened instead?:
Tests should passed, but negativ time correction is applied as positive correction.
Software version (skip for WMF-hosted wikis like Wikipedia): master (tests via https://gerrit.wikimedia.org/r/c/mediawiki/core/+/976316)
The test is calling Language::userAdjust, which calls DateTime::modify with "+{$minDiff} minutes" where $minDiff is the time correction to apply.
For negative correction this results in +-120 minutes, it seems the - is ignored in php8.2
DateTime::modify depends on strtotime to pass the modifier, but it seems that is broken:
# php -v PHP 8.2.3 (cli) (built: Feb 14 2023 09:55:52) (ZTS Visual C++ 2019 x64) # php maintenance\eval.php > echo strtotime( "@1000000000 +120 minutes" ); 1000007200 > echo strtotime( "@1000000000 -120 minutes" ); 999992800 > echo strtotime( "@1000000000 +-120 minutes" ); 1000007200
# php -v PHP 8.1.8 (cli) (built: Jul 5 2022 23:04:29) (ZTS Visual C++ 2019 x64) # php maintenance\eval.php > echo strtotime( "@1000000000 +120 minutes" ); 1000007200 > echo strtotime( "@1000000000 -120 minutes" ); 999992800 > echo strtotime( "@1000000000 +-120 minutes" ); 999992800