Commit:    ad545949d027f39dad783d9cec1f4e4b58cd3680
Author:    Stanislav Malyshev <s...@php.net>         Sat, 14 Jul 2012 21:25:55 
-0700
Parents:   7e2d550e881cba1d2a039d1bd2459831a359096c
Branches:  master

Link:       
http://git.php.net/?p=php-src.git;a=commitdiff;h=ad545949d027f39dad783d9cec1f4e4b58cd3680

Log:
fix for display of Jewish month names

Changed paths:
  M  ext/calendar/calendar.c
  M  ext/calendar/jewish.c


Diff:
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c
index 7926fad..1ab1f16 100644
--- a/ext/calendar/calendar.c
+++ b/ext/calendar/calendar.c
@@ -140,7 +140,7 @@ const zend_function_entry calendar_functions[] = {
        PHP_FE(frenchtojd, arginfo_frenchtojd)
        PHP_FE(jddayofweek, arginfo_jddayofweek)
        PHP_FE(jdmonthname, arginfo_jdmonthname)
-       PHP_FE(easter_date, arginfo_easter_date) 
+       PHP_FE(easter_date, arginfo_easter_date)
        PHP_FE(easter_days, arginfo_easter_days)
        PHP_FE(unixtojd, arginfo_unixtojd)
        PHP_FE(jdtounix, arginfo_jdtounix)
@@ -199,11 +199,14 @@ static struct cal_entry_t 
cal_conversion_table[CAL_NUM_CALS] = {
        {"Julian", "CAL_JULIAN", JulianToSdn, SdnToJulian, 12, 31,
         MonthNameShort, MonthNameLong},
        {"Jewish", "CAL_JEWISH", JewishToSdn, SdnToJewish, 13, 30,
-        JewishMonthName, JewishMonthName},
+        JewishMonthNameLeap, JewishMonthNameLeap},
        {"French", "CAL_FRENCH", FrenchToSdn, SdnToFrench, 13, 30,
         FrenchMonthName, FrenchMonthName}
 };
 
+#define JEWISH_MONTH_NAME(year)        ((monthsPerYear[(year) % 19] == 
13)?JewishMonthNameLeap:JewishMonthName)
+#define JEWISH_HEB_MONTH_NAME(year) ((monthsPerYear[(year) % 19] == 
13)?JewishMonthHebNameLeap:JewishMonthHebName)
+
 /* For jddayofweek */
 enum { CAL_DOW_DAYNO, CAL_DOW_SHORT, CAL_DOW_LONG };
 
@@ -288,7 +291,7 @@ static void _php_cal_info(int cal, zval **ret)
 PHP_FUNCTION(cal_info)
 {
        long cal = -1;
-       
+
 
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &cal) == 
FAILURE) {
                RETURN_FALSE;
@@ -418,8 +421,14 @@ PHP_FUNCTION(cal_from_jd)
        add_assoc_string(return_value, "abbrevdayname", DayNameShort[dow], 1);
        add_assoc_string(return_value, "dayname", DayNameLong[dow], 1);
 /* month name */
-       add_assoc_string(return_value, "abbrevmonth", 
calendar->month_name_short[month], 1);
-       add_assoc_string(return_value, "monthname", 
calendar->month_name_long[month], 1);
+       if(cal == CAL_JEWISH) {
+               /* special case for Jewish calendar */
+               add_assoc_string(return_value, "abbrevmonth", 
JEWISH_MONTH_NAME(year)[month], 1);
+               add_assoc_string(return_value, "monthname", 
JEWISH_MONTH_NAME(year)[month], 1);
+       } else {
+               add_assoc_string(return_value, "abbrevmonth", 
calendar->month_name_short[month], 1);
+               add_assoc_string(return_value, "monthname", 
calendar->month_name_long[month], 1);
+       }
 }
 /* }}} */
 
@@ -608,7 +617,7 @@ PHP_FUNCTION(jdtojewish)
                        RETURN_FALSE;
                }
 
-               snprintf(hebdate, sizeof(hebdate), "%s %s %s", 
heb_number_to_chars(day, fl, &dayp), JewishMonthHebName[month], 
heb_number_to_chars(year, fl, &yearp));
+               snprintf(hebdate, sizeof(hebdate), "%s %s %s", 
heb_number_to_chars(day, fl, &dayp), JEWISH_HEB_MONTH_NAME(year)[month], 
heb_number_to_chars(year, fl, &yearp));
 
                if (dayp) {
                        efree(dayp);
@@ -728,7 +737,7 @@ PHP_FUNCTION(jdmonthname)
                break;
        case CAL_MONTH_JEWISH:          /* jewish month */
                SdnToJewish(julday, &year, &month, &day);
-               monthname = JewishMonthName[month];
+               monthname = JEWISH_MONTH_NAME(year)[month];
                break;
        case CAL_MONTH_FRENCH:          /* french month */
                SdnToFrench(julday, &year, &month, &day);
diff --git a/ext/calendar/jewish.c b/ext/calendar/jewish.c
index f4dc7c3..ac256c9 100644
--- a/ext/calendar/jewish.c
+++ b/ext/calendar/jewish.c
@@ -297,9 +297,10 @@ static int yearOffset[19] =
        136, 148, 160, 173, 185, 197, 210, 222
 };
 
-char *JewishMonthName[14] =
+/* names for leap (13-month) year */
+char *JewishMonthNameLeap[14] =
 {
-       "",
+       "", 
        "Tishri",
        "Heshvan",
        "Kislev",
@@ -315,15 +316,35 @@ char *JewishMonthName[14] =
        "Elul"
 };
 
-char *JewishMonthHebName[14] =
+/* names for regular year */
+char *JewishMonthName[14] =
 {
+       "", 
+       "Tishri",
+       "Heshvan",
+       "Kislev",
+       "Tevet",
+       "Shevat",
        "",
+       "Adar",
+       "Nisan",
+       "Iyyar",
+       "Sivan",
+       "Tammuz",
+       "Av",
+       "Elul"
+};
+
+/* names for leap (13-month) year */
+char *JewishMonthHebNameLeap[14] =
+{
+       "", 
        "����",
        "����",
        "����",
        "���",
        "���",
-       "���",
+       "'��� �",
        "'��� �",
        "����",
        "����",
@@ -333,6 +354,25 @@ char *JewishMonthHebName[14] =
        "����"
 };
 
+/* names for regular year */
+char *JewishMonthHebName[14] =
+{
+       "", 
+       "����",
+       "����",
+       "����",
+       "���",
+       "���",
+       "",
+       "���",
+       "����",
+       "����",
+       "����",
+       "����",
+       "��",
+       "����"
+};
+
 /************************************************************************
  * Given the year within the 19 year metonic cycle and the time of a molad
  * (new moon) which starts that year, this routine will calculate what day
@@ -587,11 +627,11 @@ void SdnToJewish(
                                (*pMonth)--;
                                (*pDay) += 30;
                        } else {
-                               *pMonth = 6;
+                               *pMonth = 7;
                                *pDay = inputDay - tishri1 + 207;
                                if (*pDay > 0)
                                        return;
-                               (*pMonth)--;
+                               (*pMonth) -= 2;
                                (*pDay) += 30;
                        }
                        if (*pDay > 0)


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to