Add months and years to Timestamp::getHumanTimestamp()
authorJuliusz Gonera <jgonera@wikimedia.org>
Thu, 3 Jan 2013 20:57:59 +0000 (12:57 -0800)
committerJuliusz Gonera <jgonera@wikimedia.org>
Thu, 3 Jan 2013 20:57:59 +0000 (12:57 -0800)
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

includes/Timestamp.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc
tests/phpunit/includes/TimestampTest.php

index 3b7b801..630ac53 100644 (file)
@@ -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
        );
 
        /**
index e4acd18..422a4e5 100644 (file)
@@ -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',
 
index c1fb575..d8ef2df 100644 (file)
@@ -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
index 9021bef..fad1da1 100644 (file)
@@ -2816,6 +2816,8 @@ $wgMessageStructure = array(
                'minutes',
                'hours',
                'days',
+               'months',
+               'years',
                'ago',
                'just-now',
        ),
index 6352160..d7da0db 100644 (file)
@@ -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() );
        }
 
        /**