From 3c5e65927f451ec05ae1c121495fed1ec7813300 Mon Sep 17 00:00:00 2001 From: Shinjiman Date: Wed, 20 May 2009 01:53:39 +0000 Subject: [PATCH] * (bug 18849) Added Japanese and North Korean calendars support --- RELEASE-NOTES | 1 + languages/Language.php | 83 +++++++++++++++++----------- languages/messages/MessagesJa.php | 11 +++- languages/messages/MessagesKo.php | 15 ++++- languages/messages/MessagesZh_tw.php | 12 ++-- 5 files changed, 79 insertions(+), 43 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index cf39b708c9..255cf5305f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/languages/Language.php b/languages/Language.php index aa96d6f87b..b7c37beaf9 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -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 ); } /** diff --git a/languages/messages/MessagesJa.php b/languages/messages/MessagesJa.php index 21c6c62ee1..274a912294 100644 --- a/languages/messages/MessagesJa.php +++ b/languages/messages/MessagesJa.php @@ -32,15 +32,20 @@ $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( diff --git a/languages/messages/MessagesKo.php b/languages/messages/MessagesKo.php index 8962d7c73e..afb994c483 100644 --- a/languages/messages/MessagesKo.php +++ b/languages/messages/MessagesKo.php @@ -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( diff --git a/languages/messages/MessagesZh_tw.php b/languages/messages/MessagesZh_tw.php index a83a503268..2af2dce0b9 100644 --- a/languages/messages/MessagesZh_tw.php +++ b/languages/messages/MessagesZh_tw.php @@ -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)', -- 2.20.1