Remove deprecated MWTimestamp::getHumanTimestamp
Change-Id: I2374b8e1f51edd83172707fdfd2ad27ca89ad4ef
This commit is contained in:
parent
996d019b0f
commit
1d2d7ef85b
4 changed files with 2 additions and 167 deletions
|
|
@ -156,6 +156,7 @@ because of Phabricator reports.
|
|||
* Global function wfQueriesMustScale, deprecated since 1.39, has been removed.
|
||||
* Global function wfLogProfilingData, deprecated since 1.38, has been removed.
|
||||
* Linker::normaliseSpecialPage(), deprecated since 1.35, has been removed.
|
||||
* MWTimestamp::getHumanTimestamp(), deprecated since 1.26, has been removed.
|
||||
* JobQueueGroup::singleton() and ::destroySingletons(), deprecated since 1.37,
|
||||
have been removed.
|
||||
* Collation::singleton() and ::factory(), deprecated since 1.37, have been
|
||||
|
|
|
|||
|
|
@ -47,35 +47,6 @@ class MWTimestamp extends ConvertibleTimestamp {
|
|||
return new static( $ts );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the timestamp in a human-friendly relative format, e.g., "3 days ago".
|
||||
*
|
||||
* Determine the difference between the timestamp and the current time, and
|
||||
* generate a readable timestamp by returning "<N> <units> ago", where the
|
||||
* largest possible unit is used.
|
||||
*
|
||||
* @since 1.20
|
||||
* @since 1.22 Uses Language::getHumanTimestamp to produce the timestamp
|
||||
* @deprecated since 1.26 Use Language::getHumanTimestamp directly
|
||||
*
|
||||
* @param MWTimestamp|null $relativeTo The base timestamp to compare to (defaults to now)
|
||||
* @param UserIdentity|null $user User the timestamp is being generated for
|
||||
* (or null to use main context's user)
|
||||
* @param Language|null $lang Language to use to make the human timestamp
|
||||
* (or null to use main context's language)
|
||||
* @return string Formatted timestamp
|
||||
*/
|
||||
public function getHumanTimestamp(
|
||||
MWTimestamp $relativeTo = null, UserIdentity $user = null, Language $lang = null
|
||||
) {
|
||||
wfDeprecated( __METHOD__, '1.26' );
|
||||
if ( $lang === null ) {
|
||||
$lang = RequestContext::getMain()->getLanguage();
|
||||
}
|
||||
|
||||
return $lang->getHumanTimestamp( $this, $relativeTo, $user );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adjust the timestamp depending on the given user's preferences.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use User;
|
|||
interface GetHumanTimestampHook {
|
||||
/**
|
||||
* Use this hook to preemptively override the human-readable timestamp
|
||||
* generated by MWTimestamp::getHumanTimestamp().
|
||||
* generated by Language::getHumanTimestamp().
|
||||
*
|
||||
* @since 1.35
|
||||
*
|
||||
|
|
|
|||
|
|
@ -7,12 +7,6 @@ use MediaWiki\User\UserIdentityValue;
|
|||
* Tests timestamp parsing and output.
|
||||
*/
|
||||
class MWTimestampTest extends MediaWikiLangTestCase {
|
||||
protected function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
// Avoid 'GetHumanTimestamp' hook
|
||||
$this->clearHook( 'GetHumanTimestamp' );
|
||||
}
|
||||
|
||||
private function setMockUserOptions( array $options ) {
|
||||
$defaults = $this->getServiceContainer()->getMainConfig()->get( 'DefaultUserOptions' );
|
||||
|
|
@ -26,137 +20,6 @@ class MWTimestampTest extends MediaWikiLangTestCase {
|
|||
$this->setService( 'UserOptionsLookup', $userOptionsLookup );
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideHumanTimestampTests
|
||||
* @covers MWTimestamp::getHumanTimestamp
|
||||
*/
|
||||
public function testHumanTimestamp(
|
||||
$tsTime, // The timestamp to format
|
||||
$currentTime, // The time to consider "now"
|
||||
$timeCorrection, // The time offset to use
|
||||
$dateFormat, // The date preference to use
|
||||
$expectedOutput, // The expected output
|
||||
$desc // Description
|
||||
) {
|
||||
$this->hideDeprecated( 'MWTimestamp::getHumanTimestamp' );
|
||||
$this->setMockUserOptions( [
|
||||
'timecorrection' => $timeCorrection,
|
||||
'date' => $dateFormat
|
||||
] );
|
||||
|
||||
$user = new UserIdentityValue( 13, 'Pamela' );
|
||||
|
||||
$tsTime = new MWTimestamp( $tsTime );
|
||||
$currentTime = new MWTimestamp( $currentTime );
|
||||
|
||||
$this->assertEquals(
|
||||
$expectedOutput,
|
||||
$tsTime->getHumanTimestamp( $currentTime, $user ),
|
||||
$desc
|
||||
);
|
||||
}
|
||||
|
||||
public static function provideHumanTimestampTests() {
|
||||
return [
|
||||
[
|
||||
'20111231170000',
|
||||
'20120101000000',
|
||||
'Offset|0',
|
||||
'mdy',
|
||||
'Yesterday at 17:00',
|
||||
'"Yesterday" across years',
|
||||
],
|
||||
[
|
||||
'20120717190900',
|
||||
'20120717190929',
|
||||
'Offset|0',
|
||||
'mdy',
|
||||
'just now',
|
||||
'"Just now"',
|
||||
],
|
||||
[
|
||||
'20120717190900',
|
||||
'20120717191530',
|
||||
'Offset|0',
|
||||
'mdy',
|
||||
'6 minutes ago',
|
||||
'X minutes ago',
|
||||
],
|
||||
[
|
||||
'20121006173100',
|
||||
'20121006173200',
|
||||
'Offset|0',
|
||||
'mdy',
|
||||
'1 minute ago',
|
||||
'"1 minute ago"',
|
||||
],
|
||||
[
|
||||
'20120617190900',
|
||||
'20120717190900',
|
||||
'Offset|0',
|
||||
'mdy',
|
||||
'June 17',
|
||||
'Another month'
|
||||
],
|
||||
[
|
||||
'19910130151500',
|
||||
'20120716193700',
|
||||
'Offset|0',
|
||||
'mdy',
|
||||
'January 30, 1991',
|
||||
'Different year',
|
||||
],
|
||||
[
|
||||
'20120101050000',
|
||||
'20120101080000',
|
||||
'Offset|-360',
|
||||
'mdy',
|
||||
'Yesterday at 23:00',
|
||||
'"Yesterday" across years with time correction',
|
||||
],
|
||||
[
|
||||
'20120714184300',
|
||||
'20120716184300',
|
||||
'Offset|-420',
|
||||
'mdy',
|
||||
'Saturday at 11:43',
|
||||
'Recent weekday with time correction',
|
||||
],
|
||||
[
|
||||
'20120714184300',
|
||||
'20120715040000',
|
||||
'Offset|-420',
|
||||
'mdy',
|
||||
'11:43',
|
||||
'Today at another time with time correction',
|
||||
],
|
||||
[
|
||||
'20120617190900',
|
||||
'20120717190900',
|
||||
'Offset|0',
|
||||
'dmy',
|
||||
'17 June',
|
||||
'Another month with dmy'
|
||||
],
|
||||
[
|
||||
'20120617190900',
|
||||
'20120717190900',
|
||||
'Offset|0',
|
||||
'ISO 8601',
|
||||
'06-17',
|
||||
'Another month with ISO-8601'
|
||||
],
|
||||
[
|
||||
'19910130151500',
|
||||
'20120716193700',
|
||||
'Offset|0',
|
||||
'ISO 8601',
|
||||
'1991-01-30',
|
||||
'Different year with ISO-8601',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideRelativeTimestampTests
|
||||
* @covers MWTimestamp::getRelativeTimestamp
|
||||
|
|
|
|||
Loading…
Reference in a new issue