* (bug 18849) Added Japanese and North Korean calendars support
authorShinjiman <shinjiman@users.mediawiki.org>
Wed, 20 May 2009 01:53:39 +0000 (01:53 +0000)
committerShinjiman <shinjiman@users.mediawiki.org>
Wed, 20 May 2009 01:53:39 +0000 (01:53 +0000)
RELEASE-NOTES
languages/Language.php
languages/messages/MessagesJa.php
languages/messages/MessagesKo.php
languages/messages/MessagesZh_tw.php

index cf39b70..255cf53 100644 (file)
@@ -62,6 +62,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * Added Minguo calendar support for the Taiwan Chinese language
 * Database: unionQueries function to be used for UNION sql construction, so 
   it can be overloaded on DB abstraction level for DB specific functionality
+* (bug 18849) Implement Japanese and North Korean calendars
 
 === Bug fixes in 1.16 ===
 
index aa96d6f..b7c37be 100644 (file)
@@ -567,7 +567,10 @@ class Language {
         *
         *    xkY  Y (full year) in Thai solar calendar. Months and days are
         *                       identical to the Gregorian calendar
-        *    xoY  Y (full year) in Minguo calendar. Months and days are
+        *    xoY  Y (full year) in Minguo calendar or Juche year.
+        *                       Months and days are identical to the
+        *                       Gregorian calendar
+        *    xtY  Y (full year) in Japanese nengo. Months and days are
         *                       identical to the Gregorian calendar
         *
         * Characters enclosed in double quotes will be considered literal (with
@@ -601,6 +604,7 @@ class Language {
                $hijri = false;
                $thai = false;
                $minguo = false;
+               $tenno = false;
                for ( $p = 0; $p < strlen( $format ); $p++ ) {
                        $num = false;
                        $code = $format[$p];
@@ -608,7 +612,7 @@ class Language {
                                $code .= $format[++$p];
                        }
 
-                       if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' || $code == 'xm' || $code == 'xo' ) && $p < strlen( $format ) - 1 ) {
+                       if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' || $code == 'xm' || $code == 'xo' || $code == 'xt' ) && $p < strlen( $format ) - 1 ) {
                                $code .= $format[++$p];
                        }
 
@@ -752,13 +756,17 @@ class Language {
                                        $num = $hebrew[0];
                                        break;
                                case 'xkY':
-                                       if ( !$thai ) $thai = self::tsToThai( $ts );
+                                       if ( !$thai ) $thai = self::tsToYear( $ts, 'thai' );
                                        $num = $thai[0];
                                        break;
                                case 'xoY':
-                                       if ( !$minguo ) $minguo = self::tsToMinguo( $ts );
+                                       if ( !$minguo ) $minguo = self::tsToYear( $ts, 'minguo' );
                                        $num = $minguo[0];
                                        break;
+                               case 'xtY':
+                                       if ( !$tenno ) $tenno = self::tsToYear( $ts, 'tenno' );
+                                       $num = $tenno[0];
+                                       break;
                                case 'y':
                                        $num = substr( $ts, 2, 2 );
                                        break;
@@ -1120,43 +1128,56 @@ class Language {
        }
 
        /**
-        * Algorithm to convert Gregorian dates to Thai solar dates.
+        * Algorithm to convert Gregorian dates to Thai solar dates,
+        * Minguo dates or Minguo dates.
         *
         * Link: http://en.wikipedia.org/wiki/Thai_solar_calendar
+        *       http://en.wikipedia.org/wiki/Minguo_calendar
+        *       http://en.wikipedia.org/wiki/Japanese_era_name
         *
-        * @param $ts String: 14-character timestamp
+        * @param $ts String: 14-character timestamp, calender name
         * @return array converted year, month, day
         */
-       private static function tsToThai( $ts ) {
+       private static function tsToYear( $ts, $cName ) {
                $gy = substr( $ts, 0, 4 );
                $gm = substr( $ts, 4, 2 );
                $gd = substr( $ts, 6, 2 );
 
-               # Add 543 years to the Gregorian calendar
-               # Months and days are identical
-               $gy_thai = $gy + 543;
-
-               return array( $gy_thai, $gm, $gd );
-       }
-
-       /**
-        * Algorithm to convert Gregorian dates to Minguo dates.
-        *
-        * Link: http://en.wikipedia.org/wiki/Minguo_calendar
-        *
-        * @param $ts String: 14-character timestamp
-        * @return array converted year, month, day
-        */
-       private static function tsToMinguo( $ts ) {
-               $gy = substr( $ts, 0, 4 );
-               $gm = substr( $ts, 4, 2 );
-               $gd = substr( $ts, 6, 2 );
-
-               # Deduct 1911 years from the Gregorian calendar
-               # Months and days are identical
-               $gy_minguo = $gy - 1911;
+               if (!strcmp($cName,'thai')) {
+                       # Thai solar dates
+                       # Add 543 years to the Gregorian calendar
+                       # Months and days are identical
+                       $gy_offset = $gy + 543;
+               } else if ((!strcmp($cName,'minguo')) || !strcmp($cName,'juche')) {
+                       # Minguo dates
+                       # Deduct 1911 years from the Gregorian calendar
+                       # Months and days are identical
+                       $gy_offset = $gy - 1911;
+               } else if (!strcmp($cName,'tenno')) {
+                       # Minguo dates up to Showa period
+                       # Deduct years from the Gregorian calendar
+                       # depending on the nengo periods
+                       # Months and days are identical
+                       if (($gy < 1989) || (($gy == 1989) && ($gm == 1) && ($gd < 8))) {
+                               # Shōwa period
+                               $gy_gannen = $gy - 1926 + 1;
+                               $gy_offset = $gy_gannen + $gy_offset;
+                               if ($gy_gannen == 1)
+                                       $gy_offset = '元';
+                               $gy_offset = '昭和'.$gy_offset;
+                       } else {
+                               # Heisei period
+                               $gy_gannen = $gy - 1989 + 1;
+                               $gy_offset = $gy_gannen + $gy_offset;
+                               if ($gy_gannen == 1)
+                                       $gy_offset = '元';
+                               $gy_offset = '平成'.$gy_offset;
+                       }
+               } else {
+                       $gy_offset = $gy;
+               }
 
-               return array( $gy_minguo, $gm, $gd );
+               return array( $gy_offset, $gm, $gd );
        }
 
        /**
index 21c6c62..274a912 100644 (file)
 
 $datePreferences = array(
        'default',
+       'nengo',
        'ISO 8601',
 );
 
 $defaultDateFormat = 'ja';
 
 $dateFormats = array(
-       'ja time' => 'H:i',
-       'ja date' => 'Y年n月j日 (D)',
-       'ja both' => 'Y年n月j日 (D) H:i',
+       'ja time'    => 'H:i',
+       'ja date'    => 'Y年n月j日 (D)',
+       'ja both'    => 'Y年n月j日 (D) H:i',
+
+       'nengo time' => 'H:i',
+       'nengo date' => 'xtY年n月j日 (D)',
+       'nengo both' => 'xtY年n月j日 (D) H:i',
 );
 
 $namespaceNames = array(
index 8962d7c..afb994c 100644 (file)
@@ -247,11 +247,20 @@ $bookstoreList = array(
        'inherit' => true,
 );
 
+$datePreferences = array(
+       'default',
+       'juche',
+       'ISO 8601',
+);
 $defaultDateFormat = 'ko';
 $dateFormats = array(
-       'ko time' => 'H:i',
-       'ko date' => 'Y년 M월 j일 (D)',
-       'ko both' => 'Y년 M월 j일 (D) H:i',
+       'ko time'    => 'H:i',
+       'ko date'    => 'Y년 M월 j일 (D)',
+       'ko both'    => 'Y년 M월 j일 (D) H:i',
+
+       'juche time' => 'H:i',
+       'juche date' => 'xoY년 M월 j일 (D)',
+       'juche both' => 'xoY년 M월 j일 (D) H:i',
 );
 
 $messages = array(
index a83a503..2af2dce 100644 (file)
@@ -48,13 +48,13 @@ $datePreferences = array(
 $defaultDateFormat = 'zh';
 
 $dateFormats = array(
-       'zh time' => 'H:i',
-       'zh date' => 'Y年n月j日 (l)',
-       'zh both' => 'Y年n月j日 (D) H:i',
+       'zh time'       => 'H:i',
+       'zh date'       => 'Y年n月j日 (l)',
+       'zh both'       => 'Y年n月j日 (D) H:i',
 
-       'minguo time' => 'H:i',
-       'minguo date' => 'xoY年n月j日 (l)',
-       'minguo both' => 'xoY年n月j日 (D) H:i',
+       'minguo time'   => 'H:i',
+       'minguo date'   => 'xoY年n月j日 (l)',
+       'minguo both'   => 'xoY年n月j日 (D) H:i',
 
        'CNS 7648 time' => 'H:i',
        'CNS 7648 date' => 'R.O.C. xoY-m-d (l)',