3 use MediaWiki\MainConfigNames
;
7 * @covers \MediaWiki\Language\Language::userAdjust
9 class TimeAdjustTest
extends MediaWikiLangTestCase
{
10 private const LOCAL_TZ_OFFSET
= 17;
13 * Test offset usage for a given Language::userAdjust
14 * @dataProvider dataUserAdjust
16 public function testUserAdjust( string $date, $correction, string $expected ) {
17 $this->overrideConfigValue( MainConfigNames
::LocalTZoffset
, self
::LOCAL_TZ_OFFSET
);
21 $this->getServiceContainer()->getContentLanguage()->userAdjust( $date, $correction )
25 public static function dataUserAdjust() {
26 // Note: make sure to use dates in the past, especially with geographical time zones, to avoid any
27 // chance of tests failing due to a change to the time zone rules.
28 yield
'Literal int 0 (technically undocumented)' => [ '20221015120000', 0, '20221015120000' ];
29 yield
'Literal int 2 (technically undocumented)' => [ '20221015120000', 2, '20221015140000' ];
30 yield
'Literal int -2 (technically undocumented)' => [ '20221015120000', -2, '20221015100000' ];
32 yield
'Literal 0' => [ '20221015120000', '0', '20221015120000' ];
33 yield
'Literal 5' => [ '20221015120000', '5', '20221015170000' ];
34 yield
'Literal -5' => [ '20221015120000', '-5', '20221015070000' ];
37 '+00:00' => [ '20221015120000', '20221015120000', 0 ],
38 '+02:00' => [ '20221015120000', '20221015140000', 2 * 60 ],
39 '+02:15' => [ '20221015120000', '20221015141500', 2.25 * 60 ],
40 '+14:00' => [ '20221015120000', '20221016020000', 14 * 60 ],
41 '-06:00' => [ '20221015120000', '20221015060000', -6 * 60 ],
42 '-06:45' => [ '20221015120000', '20221015051500', -6.75 * 60 ],
43 '-12:00' => [ '20221015120000', '20221015000000', -12 * 60 ],
45 foreach ( $offsetsData as $offset => [ $time, $expected, $minutesVal ] ) {
46 yield
"Literal $offset" => [ $time, $offset, $expected ];
47 yield
"Full format $offset" => [ $time, "Offset|$minutesVal", $expected ];
49 yield
'Literal +15:00, capped at +14' => [ '20221015120000', '+15:00', '20221016020000' ];
50 yield
'Full format +15:00, capped at +14' => [ '20221015120000', 'Offset|' . ( 15 * 60 ), '20221016020000' ];
51 yield
'Literal -13:00, capped at -12' => [ '20221015120000', '-13:00', '20221015000000' ];
52 yield
'Full format -13:00, capped at -12' => [ '20221015120000', 'Offset|' . ( -13 * 60 ), '20221015000000' ];
54 yield
'Geo: Europe/Rome when +2 and +2 is stored' => [
56 'ZoneInfo|120|Europe/Rome',
59 yield
'Geo: Europe/Rome when +2 and +1 is stored' => [
61 'ZoneInfo|60|Europe/Rome',
64 yield
'Geo: Europe/Rome when +1 and +2 is stored' => [
66 'ZoneInfo|120|Europe/Rome',
69 yield
'Geo: Europe/Rome when +1 and +1 is stored' => [
71 'ZoneInfo|60|Europe/Rome',
75 yield
'Invalid geographical zone, fall back to offset' => [
77 'ZoneInfo|42|Eriador/Hobbiton',
81 // These fall back to the local offset
82 yield
'System 0, fallback to local offset' => [ '20221015120000', 'System|0', '20221015121700' ];
83 yield
'System 120, fallback to local offset' => [ '20221015120000', 'System|120', '20221015121700' ];
84 yield
'System -60, fallback to local offset' => [ '20221015120000', 'System|-60', '20221015121700' ];
86 yield
'Garbage, fallback to local offset' => [ '20221015120000', 'WhatAmIEvenDoingHere', '20221015121700' ];
87 yield
'Empty string, fallback to local offset' => [ '20221015120000', '', '20221015121700' ];
89 yield
'T32148 - local date in year 10000' => [
91 'ZoneInfo|600|Asia/Vladivostok',
94 yield
'T32148 - date in year 10000 due to local offset' => [