From: Juliusz Gonera Date: Thu, 3 Jan 2013 20:57:59 +0000 (-0800) Subject: Add months and years to Timestamp::getHumanTimestamp() X-Git-Tag: 1.31.0-rc.0~21161^2 X-Git-Url: http://git.cyclocoop.org/%24dirpuce/puce%24spip_lang_rtl.gif?a=commitdiff_plain;h=424dcde4fe136cf916bb3c5a7a46724e9d9a9300;p=lhc%2Fweb%2Fwiklou.git Add months and years to Timestamp::getHumanTimestamp() Now if the difference between $now and $then is >= 30 days, "X months ago" or "X years ago" is returned. Month is defined as 30 days, but it shouldn't cause problems in this case. The "X time ago" messages are approximate anyway. Change-Id: I228a11e23783484b64c29db94c3607a415fa81a8 --- diff --git a/includes/Timestamp.php b/includes/Timestamp.php index 3b7b801bd3..630ac5357f 100644 --- a/includes/Timestamp.php +++ b/includes/Timestamp.php @@ -54,7 +54,9 @@ class MWTimestamp { "seconds" => 1000, // 1000 milliseconds per second "minutes" => 60, // 60 seconds per minute "hours" => 60, // 60 minutes per hour - "days" => 24 // 24 hours per day + "days" => 24, // 24 hours per day + "months" => 30, // approximately 30 days per month + "years" => 12, // 12 months per year ); /** diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index e4acd18bde..422a4e5dee 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -3885,6 +3885,8 @@ By executing it, your system may be compromised.", 'minutes' => '{{PLURAL:$1|$1 minute|$1 minutes}}', 'hours' => '{{PLURAL:$1|$1 hour|$1 hours}}', 'days' => '{{PLURAL:$1|$1 day|$1 days}}', +'months' => '{{PLURAL:$1|$1 month|$1 months}}', +'years' => '{{PLURAL:$1|$1 year|$1 years}}', 'ago' => '$1 ago', 'just-now' => 'just now', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index c1fb575b3b..d8ef2dfbcd 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -6947,11 +6947,20 @@ See also {{msg-mw|Days-abbrev}} Part of variable $1 in {{msg-mw|Ago}} {{Identical|Day}}', +'months' => 'Full word for "months". $1 is the number of months. + +Part of variable $1 in {{msg-mw|Ago}}', +'years' => 'Full word for "years". $1 is the number of years. + +Part of variable $1 in {{msg-mw|Ago}}', 'ago' => 'Phrase for indicating how long ago something happened. $1 is something like "3 days 10 hours", taken from these messages: *{{msg-mw|Seconds}} *{{msg-mw|Minutes}} *{{msg-mw|Hours}} -*{{msg-mw|Days}}', +*{{msg-mw|Days}} +*{{msg-mw|Months}} +*{{msg-mw|Years}}', + 'just-now' => 'Phrase for indicating something happened just now.', # Bad image list diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 9021befe5c..fad1da1cb7 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -2816,6 +2816,8 @@ $wgMessageStructure = array( 'minutes', 'hours', 'days', + 'months', + 'years', 'ago', 'just-now', ), diff --git a/tests/phpunit/includes/TimestampTest.php b/tests/phpunit/includes/TimestampTest.php index 6352160b2c..d7da0dbe18 100644 --- a/tests/phpunit/includes/TimestampTest.php +++ b/tests/phpunit/includes/TimestampTest.php @@ -55,6 +55,10 @@ class TimestampTest extends MediaWikiTestCase { function testHumanOutput() { $timestamp = new MWTimestamp( time() - 3600 ); $this->assertEquals( "1 hour ago", $timestamp->getHumanTimestamp()->inLanguage( 'en' )->text() ); + $timestamp = new MWTimestamp( time() - 5184000 ); + $this->assertEquals( "2 months ago", $timestamp->getHumanTimestamp()->inLanguage( 'en' )->text() ); + $timestamp = new MWTimestamp( time() - 31536000 ); + $this->assertEquals( "1 year ago", $timestamp->getHumanTimestamp()->inLanguage( 'en' )->text() ); } /**