| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\MainConfigNames; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
class TimeAdjustTest extends MediaWikiLangTestCase { |
| 10 |
private const LOCAL_TZ_OFFSET = 17; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
public function testUserAdjust( string $date, $correction, string $expected ) { |
| 17 |
$this->overrideConfigValue( MainConfigNames::LocalTZoffset, self::LOCAL_TZ_OFFSET ); |
| 18 |
|
| 19 |
$this->assertSame( |
| 20 |
$expected, |
| 21 |
$this->getServiceContainer()->getContentLanguage()->userAdjust( $date, $correction ) |
| 22 |
); |
| 23 |
} |
| 24 |
|
| 25 |
public static function dataUserAdjust() { |
| 26 |
|
| 27 |
|
| 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' ]; |
| 31 |
|
| 32 |
yield 'Literal 0' => [ '20221015120000', '0', '20221015120000' ]; |
| 33 |
yield 'Literal 5' => [ '20221015120000', '5', '20221015170000' ]; |
| 34 |
yield 'Literal -5' => [ '20221015120000', '-5', '20221015070000' ]; |
| 35 |
|
| 36 |
$offsetsData = [ |
| 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 ], |
| 44 |
]; |
| 45 |
foreach ( $offsetsData as $offset => [ $time, $expected, $minutesVal ] ) { |
| 46 |
yield "Literal $offset" => [ $time, $offset, $expected ]; |
| 47 |
yield "Full format $offset" => [ $time, "Offset|$minutesVal", $expected ]; |
| 48 |
} |
| 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' ]; |
| 53 |
|
| 54 |
yield 'Geo: Europe/Rome when +2 and +2 is stored' => [ |
| 55 |
'20221015120000', |
| 56 |
'ZoneInfo|120|Europe/Rome', |
| 57 |
'20221015140000' |
| 58 |
]; |
| 59 |
yield 'Geo: Europe/Rome when +2 and +1 is stored' => [ |
| 60 |
'20221015120000', |
| 61 |
'ZoneInfo|60|Europe/Rome', |
| 62 |
'20221015140000' |
| 63 |
]; |
| 64 |
yield 'Geo: Europe/Rome when +1 and +2 is stored' => [ |
| 65 |
'20220320120000', |
| 66 |
'ZoneInfo|120|Europe/Rome', |
| 67 |
'20220320130000' |
| 68 |
]; |
| 69 |
yield 'Geo: Europe/Rome when +1 and +1 is stored' => [ |
| 70 |
'20220320120000', |
| 71 |
'ZoneInfo|60|Europe/Rome', |
| 72 |
'20220320130000' |
| 73 |
]; |
| 74 |
|
| 75 |
yield 'Invalid geographical zone, fall back to offset' => [ |
| 76 |
'20221015120000', |
| 77 |
'ZoneInfo|42|Eriador/Hobbiton', |
| 78 |
'20221015124200' |
| 79 |
]; |
| 80 |
|
| 81 |
|
| 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' ]; |
| 85 |
|
| 86 |
yield 'Garbage, fallback to local offset' => [ '20221015120000', 'WhatAmIEvenDoingHere', '20221015121700' ]; |
| 87 |
yield 'Empty string, fallback to local offset' => [ '20221015120000', '', '20221015121700' ]; |
| 88 |
|
| 89 |
yield 'T32148 - local date in year 10000' => [ |
| 90 |
'99991231235959', |
| 91 |
'ZoneInfo|600|Asia/Vladivostok', |
| 92 |
'99991231235959' |
| 93 |
]; |
| 94 |
yield 'T32148 - date in year 10000 due to local offset' => [ |
| 95 |
'99991231235959', |
| 96 |
'System|0', |
| 97 |
'99991231235959' |
| 98 |
]; |
| 99 |
} |
| 100 |
} |