Index: trunk/phase3/languages/Language.php |
— | — | @@ -509,6 +509,7 @@ |
510 | 510 | * |
511 | 511 | * xjj j (day number) in Hebrew calendar |
512 | 512 | * xjF F (month name) in Hebrew calendar |
| 513 | + * xjt t (days in month) in Hebrew calendar |
513 | 514 | * xjx xg (genitive month name) in Hebrew calendar |
514 | 515 | * xjn n (month number) in Hebrew calendar |
515 | 516 | * xjY Y (full year) in Hebrew calendar |
— | — | @@ -648,6 +649,10 @@ |
649 | 650 | if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
650 | 651 | $num = gmdate( 't', $unix ); |
651 | 652 | break; |
| 653 | + case 'xjt': |
| 654 | + if ( !$hebrew ) $hebrew = self::tsToHebrew( $ts ); |
| 655 | + $num = $hebrew[3]; |
| 656 | + break; |
652 | 657 | case 'L': |
653 | 658 | if ( !$unix ) $unix = wfTimestamp( TS_UNIX, $ts ); |
654 | 659 | $num = gmdate( 'L', $unix ); |
— | — | @@ -829,27 +834,27 @@ |
830 | 835 | # Month number when March = 1, February = 12 |
831 | 836 | $month -= 2; |
832 | 837 | if( $month <= 0 ) { |
833 | | - # January of February |
| 838 | + # January or February |
834 | 839 | $month += 12; |
835 | 840 | $year--; |
836 | 841 | } |
837 | 842 | |
838 | 843 | # Days since 1 March - calculating 30 days a month, |
839 | 844 | # and then adding the missing number of days |
840 | | - $day += intval( 7 * $month / 12 + 30 * ( $month - 1 ) ); |
| 845 | + $dayOfYear = $day + intval( 7 * $month / 12 + 30 * ( $month - 1 ) ); |
841 | 846 | # Calculate Hebrew year for days after 1 Nisan |
842 | 847 | $hebrewYear = $year + 3760; |
843 | 848 | # Passover date for this year (as days since 1 March) |
844 | 849 | $passover = self::passoverDate( $hebrewYear ); |
845 | | - if( $day <= $passover - 15 ) { |
| 850 | + if( $dayOfYear <= $passover - 15 ) { |
846 | 851 | # Day is before 1 Nisan (passover is 15 Nisan) - it is the previous year |
847 | 852 | # Next year's passover (as days since 1 March) |
848 | 853 | $anchor = $passover; |
849 | 854 | # Add days since previous year's 1 March |
850 | | - $day += 365; |
| 855 | + $dayOfYear += 365; |
851 | 856 | if( ( $year % 400 == 0 ) || ( $year % 100 != 0 && $year % 4 == 0 ) ) { |
852 | 857 | # Leap year |
853 | | - $day++; |
| 858 | + $dayOfYear++; |
854 | 859 | } |
855 | 860 | # Previous year |
856 | 861 | $year--; |
— | — | @@ -862,7 +867,7 @@ |
863 | 868 | } |
864 | 869 | |
865 | 870 | # Days since 1 Nisan |
866 | | - $day -= $passover - 15; |
| 871 | + $dayOfYear -= $passover - 15; |
867 | 872 | # Difference between this year's passover date by gregorian calendar, |
868 | 873 | # and the next year's one + 12 days. This should be 1 days for a regular year, |
869 | 874 | # but 0 for incomplete one, 2 for complete, and those + 30 days of Adar I |
— | — | @@ -874,15 +879,22 @@ |
875 | 880 | $anchor++; |
876 | 881 | } |
877 | 882 | |
| 883 | + # Check the year pattern |
| 884 | + # 0 means an incomplete year, 1 means a regular year, 2 means a complete year |
| 885 | + # This is mod 30, to work on both leap years (which add 30 days of Adar I) |
| 886 | + # and non-leap years |
| 887 | + $yearPattern = $anchor % 30; |
| 888 | + |
878 | 889 | # Calculate day in the month from number of days sine 1 Nisan |
879 | | - # Don't check Adar - if the day is not in adar, we will stop before; |
880 | | - # if it is in adar, we will use it to check if it is Adar I or Adar II |
| 890 | + # Don't check Adar - if the day is not in Adar, we will stop before; |
| 891 | + # if it is in Adar, we will use it to check if it is Adar I or Adar II |
| 892 | + $day = $dayOfYear; |
881 | 893 | for( $month = 0; $month < 11; $month++ ) { |
882 | 894 | # Calculate days in this month |
883 | | - if( $month == 7 && $anchor % 30 == 2 ) { |
| 895 | + if( $month == 7 && $yearPattern == 2 ) { |
884 | 896 | # Cheshvan in a complete year (otherwise as the rule below) |
885 | 897 | $days = 30; |
886 | | - } else if( $month == 8 && $anchor % 30 == 0 ) { |
| 898 | + } else if( $month == 8 && $yearPattern == 0 ) { |
887 | 899 | # Kislev in an incomplete year (otherwise as the rule below) |
888 | 900 | $days = 29; |
889 | 901 | } else { |
— | — | @@ -905,44 +917,31 @@ |
906 | 918 | # Recalculate month number so that we start from Tishrei |
907 | 919 | $month = ( $month + 6 ) % 12 + 1; |
908 | 920 | |
909 | | - # Fix Adar |
910 | | - if( $month == 6 && $anchor >= 30 ) { |
911 | | - # This *is* adar, and this year is leap |
912 | | - if( $day > 30 ) { |
913 | | - # Adar II |
914 | | - $month = 14; |
915 | | - $day -= 30; |
| 921 | + # Get Adar type and number of days |
| 922 | + if( $month == 6 ) { |
| 923 | + # Adar |
| 924 | + if( $anchor >= 30 ) { |
| 925 | + # Leap year - check type and set number of days |
| 926 | + if( $day > 30 ) { |
| 927 | + # Adar II - 29 days |
| 928 | + $month = 14; |
| 929 | + $day -= 30; |
| 930 | + $days = 29; |
| 931 | + } else { |
| 932 | + # Adar I - 30 days |
| 933 | + $month = 13; |
| 934 | + $days = 30; |
| 935 | + } |
916 | 936 | } else { |
917 | | - # Adar I |
918 | | - $month = 13; |
| 937 | + # Non-leap year - just set number of days (29) |
| 938 | + $days = 29; |
919 | 939 | } |
920 | 940 | } |
921 | 941 | |
922 | | - return array( $hebrewYear, $month, $day ); |
| 942 | + return array( $hebrewYear, $month, $day, $days ); |
923 | 943 | } |
924 | 944 | |
925 | 945 | /** |
926 | | - * Algorithm to convert Gregorian dates to Thai solar dates. |
927 | | - * |
928 | | - * Link: http://en.wikipedia.org/wiki/Thai_solar_calendar |
929 | | - * |
930 | | - * @param string $ts 14-character timestamp |
931 | | - * @return array converted year, month, day |
932 | | - */ |
933 | | - private static function tsToThai( $ts ) { |
934 | | - $gy = substr( $ts, 0, 4 ); |
935 | | - $gm = substr( $ts, 4, 2 ); |
936 | | - $gd = substr( $ts, 6, 2 ); |
937 | | - |
938 | | - # Add 543 years to the Gregorian calendar |
939 | | - # Months and days are identical |
940 | | - $gy_thai = $gy + 543; |
941 | | - |
942 | | - return array( $gy_thai, $gm, $gd ); |
943 | | - } |
944 | | - |
945 | | - |
946 | | - /** |
947 | 946 | * Based on Carl Friedrich Gauss algorithm for finding Easter date. |
948 | 947 | * Used for Hebrew date. |
949 | 948 | */ |
— | — | @@ -973,6 +972,27 @@ |
974 | 973 | } |
975 | 974 | |
976 | 975 | /** |
| 976 | + * Algorithm to convert Gregorian dates to Thai solar dates. |
| 977 | + * |
| 978 | + * Link: http://en.wikipedia.org/wiki/Thai_solar_calendar |
| 979 | + * |
| 980 | + * @param string $ts 14-character timestamp |
| 981 | + * @return array converted year, month, day |
| 982 | + */ |
| 983 | + private static function tsToThai( $ts ) { |
| 984 | + $gy = substr( $ts, 0, 4 ); |
| 985 | + $gm = substr( $ts, 4, 2 ); |
| 986 | + $gd = substr( $ts, 6, 2 ); |
| 987 | + |
| 988 | + # Add 543 years to the Gregorian calendar |
| 989 | + # Months and days are identical |
| 990 | + $gy_thai = $gy + 543; |
| 991 | + |
| 992 | + return array( $gy_thai, $gm, $gd ); |
| 993 | + } |
| 994 | + |
| 995 | + |
| 996 | + /** |
977 | 997 | * Roman number formatting up to 3000 |
978 | 998 | */ |
979 | 999 | static function romanNumeral( $num ) { |