Fix the bug for dates between 1912 and 1941 in Thai language
authorsuperyetkin <superyetkin@yahoo.com>
Sat, 21 Apr 2018 21:12:02 +0000 (00:12 +0300)
committerSuperyetkin <superyetkin@yahoo.com>
Sat, 12 May 2018 15:10:13 +0000 (15:10 +0000)
Added an if-else block to see if the parameters passed to the function
designate a year between 1912 and 1941 or not. Resulting month values
are also adjusted.
Added a unit test for the related formatting.

Bug: T68648
Change-Id: Ic676b5c140de8878971a786a1a1811770a848016

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

index d750f7d..0941e3d 100644 (file)
@@ -1884,6 +1884,14 @@ class Language {
                        # Add 543 years to the Gregorian calendar
                        # Months and days are identical
                        $gy_offset = $gy + 543;
+                       # fix for dates between 1912 and 1941
+                       # https://en.wikipedia.org/?oldid=836596673#New_year
+                       if ( $gy >= 1912 && $gy <= 1940 ) {
+                               if ( $gm <= 3 ) {
+                                       $gy_offset--;
+                               }
+                               $gm = ( $gm - 3 ) % 12;
+                       }
                } elseif ( ( !strcmp( $cName, 'minguo' ) ) || !strcmp( $cName, 'juche' ) ) {
                        # Minguo dates
                        # Deduct 1911 years from the Gregorian calendar
index 050ed83..04ffdab 100644 (file)
@@ -1029,6 +1029,13 @@ class LanguageTest extends LanguageClassesTestCase {
                                '2555',
                                'Thai year'
                        ],
+                       [
+                               'xkY',
+                               '19410101090705',
+                               '2484',
+                               '2484',
+                               'Thai year'
+                       ],
                        [
                                'xoY',
                                '20120102090705',