Page MenuHomePhabricator

TimeAdjustTest::testUserAdjust failure under php8.2 (strtotime handling of multiple signs changed)
Closed, ResolvedPublicBUG REPORT

Description

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

Event Timeline

https://github.com/php/php-src/issues/9950
https://github.com/php/doc-en/commit/ef51b1ce007349e7ff415ec5c707f1b5a73aba27

number symbols in relative formats no longer accept multiple signs, e.g. +-2

Not sure about impact about all the strtotime in the code and possible values stored in the database.

Umherirrender renamed this task from TimeAdjustTest::testUserAdjust failure under php8.2 (strtotime handling of +- changed) to TimeAdjustTest::testUserAdjust failure under php8.2 (strtotime handling of multiple signs changed).Nov 22 2023, 8:35 PM

Change 976851 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@master] language: Avoid multiple signs in Language::userAdjust

https://gerrit.wikimedia.org/r/976851

Change 976851 merged by jenkins-bot:

[mediawiki/core@master] language: Avoid multiple signs in Language::userAdjust

https://gerrit.wikimedia.org/r/976851

Change 977622 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@REL1_41] language: Avoid multiple signs in Language::userAdjust

https://gerrit.wikimedia.org/r/977622

Change 977623 had a related patch set uploaded (by Umherirrender; author: Umherirrender):

[mediawiki/core@REL1_40] language: Avoid multiple signs in Language::userAdjust

https://gerrit.wikimedia.org/r/977623

Change 977622 merged by jenkins-bot:

[mediawiki/core@REL1_41] language: Avoid multiple signs in Language::userAdjust

https://gerrit.wikimedia.org/r/977622

Change 977623 merged by jenkins-bot:

[mediawiki/core@REL1_40] language: Avoid multiple signs in Language::userAdjust

https://gerrit.wikimedia.org/r/977623

Umherirrender claimed this task.
Umherirrender removed a project: Patch-For-Review.