r50804 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50803‎ | r50804 | r50805 >
Date:01:53, 20 May 2009
Author:shinjiman
Status:ok
Tags:
Comment:
* (bug 18849) Added Japanese and North Korean calendars support
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesJa.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesKo.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesZh_tw.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/messages/MessagesKo.php
@@ -247,11 +247,20 @@
248248 'inherit' => true,
249249 );
250250
 251+$datePreferences = array(
 252+ 'default',
 253+ 'juche',
 254+ 'ISO 8601',
 255+);
251256 $defaultDateFormat = 'ko';
252257 $dateFormats = array(
253 - 'ko time' => 'H:i',
254 - 'ko date' => 'Y년 M월 j일 (D)',
255 - 'ko both' => 'Y년 M월 j일 (D) H:i',
 258+ 'ko time' => 'H:i',
 259+ 'ko date' => 'Y년 M월 j일 (D)',
 260+ 'ko both' => 'Y년 M월 j일 (D) H:i',
 261+
 262+ 'juche time' => 'H:i',
 263+ 'juche date' => 'xoY년 M월 j일 (D)',
 264+ 'juche both' => 'xoY년 M월 j일 (D) H:i',
256265 );
257266
258267 $messages = array(
Index: trunk/phase3/languages/messages/MessagesZh_tw.php
@@ -48,13 +48,13 @@
4949 $defaultDateFormat = 'zh';
5050
5151 $dateFormats = array(
52 - 'zh time' => 'H:i',
53 - 'zh date' => 'Y年n月j日 (l)',
54 - 'zh both' => 'Y年n月j日 (D) H:i',
 52+ 'zh time' => 'H:i',
 53+ 'zh date' => 'Y年n月j日 (l)',
 54+ 'zh both' => 'Y年n月j日 (D) H:i',
5555
56 - 'minguo time' => 'H:i',
57 - 'minguo date' => 'xoY年n月j日 (l)',
58 - 'minguo both' => 'xoY年n月j日 (D) H:i',
 56+ 'minguo time' => 'H:i',
 57+ 'minguo date' => 'xoY年n月j日 (l)',
 58+ 'minguo both' => 'xoY年n月j日 (D) H:i',
5959
6060 'CNS 7648 time' => 'H:i',
6161 'CNS 7648 date' => 'R.O.C. xoY-m-d (l)',
Index: trunk/phase3/languages/messages/MessagesJa.php
@@ -32,15 +32,20 @@
3333
3434 $datePreferences = array(
3535 'default',
 36+ 'nengo',
3637 'ISO 8601',
3738 );
3839
3940 $defaultDateFormat = 'ja';
4041
4142 $dateFormats = array(
42 - 'ja time' => 'H:i',
43 - 'ja date' => 'Y年n月j日 (D)',
44 - 'ja both' => 'Y年n月j日 (D) H:i',
 43+ 'ja time' => 'H:i',
 44+ 'ja date' => 'Y年n月j日 (D)',
 45+ 'ja both' => 'Y年n月j日 (D) H:i',
 46+
 47+ 'nengo time' => 'H:i',
 48+ 'nengo date' => 'xtY年n月j日 (D)',
 49+ 'nengo both' => 'xtY年n月j日 (D) H:i',
4550 );
4651
4752 $namespaceNames = array(
Index: trunk/phase3/languages/Language.php
@@ -567,7 +567,10 @@
568568 *
569569 * xkY Y (full year) in Thai solar calendar. Months and days are
570570 * identical to the Gregorian calendar
571 - * xoY Y (full year) in Minguo calendar. Months and days are
 571+ * xoY Y (full year) in Minguo calendar or Juche year.
 572+ * Months and days are identical to the
 573+ * Gregorian calendar
 574+ * xtY Y (full year) in Japanese nengo. Months and days are
572575 * identical to the Gregorian calendar
573576 *
574577 * Characters enclosed in double quotes will be considered literal (with
@@ -601,6 +604,7 @@
602605 $hijri = false;
603606 $thai = false;
604607 $minguo = false;
 608+ $tenno = false;
605609 for ( $p = 0; $p < strlen( $format ); $p++ ) {
606610 $num = false;
607611 $code = $format[$p];
@@ -608,7 +612,7 @@
609613 $code .= $format[++$p];
610614 }
611615
612 - if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' || $code == 'xm' || $code == 'xo' ) && $p < strlen( $format ) - 1 ) {
 616+ if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' || $code == 'xm' || $code == 'xo' || $code == 'xt' ) && $p < strlen( $format ) - 1 ) {
613617 $code .= $format[++$p];
614618 }
615619
@@ -752,13 +756,17 @@
753757 $num = $hebrew[0];
754758 break;
755759 case 'xkY':
756 - if ( !$thai ) $thai = self::tsToThai( $ts );
 760+ if ( !$thai ) $thai = self::tsToYear( $ts, 'thai' );
757761 $num = $thai[0];
758762 break;
759763 case 'xoY':
760 - if ( !$minguo ) $minguo = self::tsToMinguo( $ts );
 764+ if ( !$minguo ) $minguo = self::tsToYear( $ts, 'minguo' );
761765 $num = $minguo[0];
762766 break;
 767+ case 'xtY':
 768+ if ( !$tenno ) $tenno = self::tsToYear( $ts, 'tenno' );
 769+ $num = $tenno[0];
 770+ break;
763771 case 'y':
764772 $num = substr( $ts, 2, 2 );
765773 break;
@@ -1120,46 +1128,59 @@
11211129 }
11221130
11231131 /**
1124 - * Algorithm to convert Gregorian dates to Thai solar dates.
 1132+ * Algorithm to convert Gregorian dates to Thai solar dates,
 1133+ * Minguo dates or Minguo dates.
11251134 *
11261135 * Link: http://en.wikipedia.org/wiki/Thai_solar_calendar
 1136+ * http://en.wikipedia.org/wiki/Minguo_calendar
 1137+ * http://en.wikipedia.org/wiki/Japanese_era_name
11271138 *
1128 - * @param $ts String: 14-character timestamp
 1139+ * @param $ts String: 14-character timestamp, calender name
11291140 * @return array converted year, month, day
11301141 */
1131 - private static function tsToThai( $ts ) {
 1142+ private static function tsToYear( $ts, $cName ) {
11321143 $gy = substr( $ts, 0, 4 );
11331144 $gm = substr( $ts, 4, 2 );
11341145 $gd = substr( $ts, 6, 2 );
11351146
1136 - # Add 543 years to the Gregorian calendar
1137 - # Months and days are identical
1138 - $gy_thai = $gy + 543;
 1147+ if (!strcmp($cName,'thai')) {
 1148+ # Thai solar dates
 1149+ # Add 543 years to the Gregorian calendar
 1150+ # Months and days are identical
 1151+ $gy_offset = $gy + 543;
 1152+ } else if ((!strcmp($cName,'minguo')) || !strcmp($cName,'juche')) {
 1153+ # Minguo dates
 1154+ # Deduct 1911 years from the Gregorian calendar
 1155+ # Months and days are identical
 1156+ $gy_offset = $gy - 1911;
 1157+ } else if (!strcmp($cName,'tenno')) {
 1158+ # Minguo dates up to Showa period
 1159+ # Deduct years from the Gregorian calendar
 1160+ # depending on the nengo periods
 1161+ # Months and days are identical
 1162+ if (($gy < 1989) || (($gy == 1989) && ($gm == 1) && ($gd < 8))) {
 1163+ # Shōwa period
 1164+ $gy_gannen = $gy - 1926 + 1;
 1165+ $gy_offset = $gy_gannen + $gy_offset;
 1166+ if ($gy_gannen == 1)
 1167+ $gy_offset = '元';
 1168+ $gy_offset = '昭和'.$gy_offset;
 1169+ } else {
 1170+ # Heisei period
 1171+ $gy_gannen = $gy - 1989 + 1;
 1172+ $gy_offset = $gy_gannen + $gy_offset;
 1173+ if ($gy_gannen == 1)
 1174+ $gy_offset = '元';
 1175+ $gy_offset = '平成'.$gy_offset;
 1176+ }
 1177+ } else {
 1178+ $gy_offset = $gy;
 1179+ }
11391180
1140 - return array( $gy_thai, $gm, $gd );
 1181+ return array( $gy_offset, $gm, $gd );
11411182 }
11421183
11431184 /**
1144 - * Algorithm to convert Gregorian dates to Minguo dates.
1145 - *
1146 - * Link: http://en.wikipedia.org/wiki/Minguo_calendar
1147 - *
1148 - * @param $ts String: 14-character timestamp
1149 - * @return array converted year, month, day
1150 - */
1151 - private static function tsToMinguo( $ts ) {
1152 - $gy = substr( $ts, 0, 4 );
1153 - $gm = substr( $ts, 4, 2 );
1154 - $gd = substr( $ts, 6, 2 );
1155 -
1156 - # Deduct 1911 years from the Gregorian calendar
1157 - # Months and days are identical
1158 - $gy_minguo = $gy - 1911;
1159 -
1160 - return array( $gy_minguo, $gm, $gd );
1161 - }
1162 -
1163 - /**
11641185 * Roman number formatting up to 3000
11651186 */
11661187 static function romanNumeral( $num ) {
Index: trunk/phase3/RELEASE-NOTES
@@ -62,6 +62,7 @@
6363 * Added Minguo calendar support for the Taiwan Chinese language
6464 * Database: unionQueries function to be used for UNION sql construction, so
6565 it can be overloaded on DB abstraction level for DB specific functionality
 66+* (bug 18849) Implement Japanese and North Korean calendars
6667
6768 === Bug fixes in 1.16 ===
6869

Follow-up revisions

RevisionCommit summaryAuthorDate
r50808* (bug 18849) follow up r50778 and r50804, additional date format for Taiwan ...shinjiman03:29, 20 May 2009
r50826follow up r50804, fix undefined variable error.shinjiman15:08, 20 May 2009
r50827follow up r50804, adding two further Japanese era names.shinjiman15:49, 20 May 2009

Status & tagging log