* (bug 11657) Support for Thai solar calendar
authorRaimond Spekking <raymond@users.mediawiki.org>
Thu, 6 Dec 2007 20:14:36 +0000 (20:14 +0000)
committerRaimond Spekking <raymond@users.mediawiki.org>
Thu, 6 Dec 2007 20:14:36 +0000 (20:14 +0000)
RELEASE-NOTES
languages/Language.php
languages/messages/MessagesTh.php

index ec5e273..be0b761 100644 (file)
@@ -91,6 +91,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 8396) Ignore out-of-date serialised message caches
 * (bug 12195) Undeleting pages now requires 'undelete' permission
 * (bug 11810) Localize displayed semicolons
+* (bug 11657) Support for Thai solar calendar
 
 === Bug fixes in 1.12 ===
 
index a6e8e9f..9cbe943 100644 (file)
@@ -513,6 +513,9 @@ class Language {
         *    xjn  n (month number) in Hebrew calendar
         *    xjY  Y (full year) in Hebrew calendar
         *
+        *    xkY  Y (full year) in Thai solar calendar. Months and days are
+        *                       identical to the Gregorian calendar
+        *
         * Characters enclosed in double quotes will be considered literal (with
         * the quotes themselves removed). Unmatched quotes will be considered
         * literal quotes. Example:
@@ -539,6 +542,7 @@ class Language {
                $rawToggle = false;
                $iranian = false;
                $hebrew = false;
+               $thai = false;
                for ( $p = 0; $p < strlen( $format ); $p++ ) {
                        $num = false;
                        $code = $format[$p];
@@ -546,7 +550,7 @@ class Language {
                                $code .= $format[++$p];
                        }
 
-                       if ( ( $code === 'xi' || $code == 'xj' ) && $p < strlen( $format ) - 1 ) {
+                       if ( ( $code === 'xi' || $code == 'xj' || $code == 'xk' ) && $p < strlen( $format ) - 1 ) {
                                $code .= $format[++$p];
                        }
 
@@ -659,6 +663,10 @@ class Language {
                                        if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts );
                                        $num = $hebrew[0];
                                        break;
+                               case 'xkY':
+                                       if ( !$thai ) $thai = self::tsToThai( $ts );
+                                       $num = $thai[0];
+                                       break;
                                case 'y':
                                        $num = substr( $ts, 2, 2 );
                                        break;
@@ -913,6 +921,27 @@ class Language {
                return array( $hebrewYear, $month, $day );
        }
 
+       /**
+        * Algorithm to convert Gregorian dates to Thai solar dates.
+        *
+        * Link: http://en.wikipedia.org/wiki/Thai_solar_calendar
+        *
+        * @param string $ts 14-character timestamp
+        * @return array converted year, month, day
+        */
+       private static function tsToThai( $ts ) {
+               $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 );
+       }
+
+
        /**
         * Based on Carl Friedrich Gauss algorithm for finding Easter date.
         * Used for Hebrew date.
index 0422d93..3381f50 100644 (file)
@@ -29,6 +29,54 @@ $namespaceNames = array(
        NS_CATEGORY_TALK    => 'คุยเรื่องหมวดหมู่',
 );
 
+/**
+ * A list of date format preference keys which can be selected in user
+ * preferences. New preference keys can be added, provided they are supported
+ * by the language class's timeanddate(). Only the 5 keys listed below are
+ * supported by the wikitext converter (DateFormatter.php).
+ *
+ * The special key "default" is an alias for either dmy or mdy depending on
+ * $wgAmericanDates
+ */
+$datePreferences = array(
+       'default',
+       'thai',
+       'mdy',
+       'dmy',
+       'ymd',
+       'ISO 8601',
+);
+
+/**
+ * These are formats for dates generated by MediaWiki (as opposed to the wikitext
+ * DateFormatter). Documentation for the format string can be found in
+ * Language.php, search for sprintfDate.
+ *
+ * This array is automatically inherited by all subclasses. Individual keys can be
+ * overridden.
+ */
+$dateFormats = array(
+       'thai time' => 'H:i',
+       'thai date' => 'j F xkY',
+       'thai both' => 'H:i, j F xkY',
+
+       'mdy time' => 'H:i',
+       'mdy date' => 'F j, Y',
+       'mdy both' => 'H:i, F j, Y',
+
+       'dmy time' => 'H:i',
+       'dmy date' => 'j F Y',
+       'dmy both' => 'H:i, j F Y',
+
+       'ymd time' => 'H:i',
+       'ymd date' => 'Y F j',
+       'ymd both' => 'H:i, Y F j',
+
+       'ISO 8601 time' => 'xnH:xni:xns',
+       'ISO 8601 date' => 'xnY-xnm-xnd',
+       'ISO 8601 both' => 'xnY-xnm-xnd"T"xnH:xni:xns',
+);
+
 $linkTrail = '/^([a-z]+)(.*)\$/sD';
 
 $messages = array(