* (bug 32461) Add two-digit short form year for Persian calendar ({{#time:xiy}})
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 14 Dec 2011 00:32:56 +0000 (00:32 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 14 Dec 2011 00:32:56 +0000 (00:32 +0000)
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.

languages/Language.php
tests/phpunit/languages/LanguageTest.php

index dfc0c8b..71cf5ea 100644 (file)
@@ -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;
index a32a5fd..401e5a3 100644 (file)
@@ -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'
+                       ),
+               );
+       }
 }