From: Brion Vibber Date: Wed, 14 Dec 2011 00:32:56 +0000 (+0000) Subject: * (bug 32461) Add two-digit short form year for Persian calendar ({{#time:xiy}}) X-Git-Tag: 1.31.0-rc.0~25979 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=f1ce2ce95217030e5f7c6025348c9d550bc7e3c8;p=lhc%2Fweb%2Fwiklou.git * (bug 32461) Add two-digit short form year for Persian calendar ({{#time:xiy}}) Patch by Platonides https://bugzilla.wikimedia.org/attachment.cgi?id=9490&action=diff Plus test case. Note the test case uses Latin-style digits because it's testing English; in fa you'd get the persian digits as in the examples on the bug. --- diff --git a/languages/Language.php b/languages/Language.php index dfc0c8b886..71cf5eab82 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -824,6 +824,7 @@ class Language { * xij j (day number) in Iranian calendar * xiF F (month name) in Iranian calendar * xin n (month number) in Iranian calendar + * xiy y (two digit year) in Iranian calendar * xiY Y (full year) in Iranian calendar * * xjj j (day number) in Hebrew calendar @@ -1086,6 +1087,12 @@ class Language { case 'y': $num = substr( $ts, 2, 2 ); break; + case 'xiy': + if ( !$iranian ) { + $iranian = self::tsToIranian( $ts ); + } + $num = substr( $iranian[0], -2 ); + break; case 'a': $s .= intval( substr( $ts, 8, 2 ) ) < 12 ? 'am' : 'pm'; break; diff --git a/tests/phpunit/languages/LanguageTest.php b/tests/phpunit/languages/LanguageTest.php index a32a5fdde4..401e5a3703 100644 --- a/tests/phpunit/languages/LanguageTest.php +++ b/tests/phpunit/languages/LanguageTest.php @@ -192,4 +192,32 @@ class LanguageTest extends MediaWikiTestCase { array( 'Be-x-old', 'With extension (two dashes)' ), ); } + + /** + * @dataProvider provideSprintfDateSamples + */ + function testSprintfDate( $format, $ts, $expected, $msg ) { + $this->assertEquals( + $expected, + $this->lang->sprintfDate( $format, $ts ), + "sprintfDate('$format', '$ts'): $msg" + ); + } + + function provideSprintfDateSamples() { + return array( + array( + 'xiY', + '20111212000000', + '1390', // note because we're testing English locale we get Latin-standard digits + 'Iranian calendar full year' + ), + array( + 'xiy', + '20111212000000', + '90', + 'Iranian calendar short year' + ), + ); + } }