From c1f44bc80f968a9cbc60a3f09c88cc7f6807b884 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Sat, 14 Jul 2012 21:25:55 -0700 Subject: [PATCH 1/5] fix for display of Jewish month names --- ext/calendar/calendar.c | 23 ++++++++++++------ ext/calendar/jewish.c | 52 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 13 deletions(-) diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c index 7926fad6714ad..1ab1f1652ebee 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 f4dc7c35ae57c..ac256c9860605 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) From 68cf829acd8d83d1f68c731b05dc1c2dc1df4bd2 Mon Sep 17 00:00:00 2001 From: Eitan Mosenkis Date: Sun, 15 Jul 2012 20:36:34 -0400 Subject: [PATCH 2/5] Update documentation to reflect fix of 54254 --- ext/calendar/jewish.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ext/calendar/jewish.c b/ext/calendar/jewish.c index ac256c9860605..494d065962346 100644 --- a/ext/calendar/jewish.c +++ b/ext/calendar/jewish.c @@ -85,8 +85,8 @@ * 3 Kislev 29 30 30 29 30 30 (variable) * 4 Tevet 29 29 29 29 29 29 * 5 Shevat 30 30 30 30 30 30 - * 6 Adar I 29 29 29 30 30 30 (variable) - * 7 Adar II -- -- -- 29 29 29 (optional) + * 6 Adar I -- -- -- 30 30 30 (optional) + * 7 Adar II 29 29 29 29 29 29 * 8 Nisan 30 30 30 30 30 30 * 9 Iyyar 29 29 29 29 29 29 * 10 Sivan 30 30 30 30 30 30 @@ -100,8 +100,8 @@ * have multiple possible spellings in the Roman character set. I have * chosen to use the spellings found in the Encyclopedia Judaica. * - * Adar II, the month added for leap years, is sometimes referred to as - * the 13th month, but I have chosen to assign it the number 7 to keep + * Adar I, the month added for leap years, is sometimes referred to as + * the 13th month, but I have chosen to assign it the number 6 to keep * the months in chronological order. This may not be consistent with * other numbering schemes. * From c94e56f591d58a5f9c412fb696a50727b82c6e9b Mon Sep 17 00:00:00 2001 From: Eitan Mosenkis Date: Thu, 19 Jul 2012 08:54:30 -0400 Subject: [PATCH 3/5] Add test for interoperability of jdtojewish and cal_days_in_month --- ext/calendar/tests/bug54254.phpt | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ext/calendar/tests/bug54254.phpt diff --git a/ext/calendar/tests/bug54254.phpt b/ext/calendar/tests/bug54254.phpt new file mode 100644 index 0000000000000..df9362320c0a6 --- /dev/null +++ b/ext/calendar/tests/bug54254.phpt @@ -0,0 +1,59 @@ +--TEST-- +Bug #54254 (cal_days_in_month incompatible with jdtojewish in non-leap-years) +--SKIPIF-- + +--FILE-- + Date: Sun, 5 Aug 2012 20:15:21 -0700 Subject: [PATCH 4/5] some fixes for bug#54254 --- ext/calendar/calendar.c | 4 ++-- ext/calendar/jewish.c | 4 ++-- ext/calendar/sdncal.h | 3 +++ ext/calendar/tests/jdmonthname.phpt | 4 ++-- ext/calendar/tests/jdtojewish.phpt | 8 +++++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c index 1ab1f1652ebee..5947aabc986b9 100644 --- a/ext/calendar/calendar.c +++ b/ext/calendar/calendar.c @@ -204,8 +204,8 @@ static struct cal_entry_t cal_conversion_table[CAL_NUM_CALS] = { 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) +#define JEWISH_MONTH_NAME(year) ((monthsPerYear[((year)-1) % 19] == 13)?JewishMonthNameLeap:JewishMonthName) +#define JEWISH_HEB_MONTH_NAME(year) ((monthsPerYear[((year)-1) % 19] == 13)?JewishMonthHebNameLeap:JewishMonthHebName) /* For jddayofweek */ enum { CAL_DOW_DAYNO, CAL_DOW_SHORT, CAL_DOW_LONG }; diff --git a/ext/calendar/jewish.c b/ext/calendar/jewish.c index 494d065962346..a5849a7d7690c 100644 --- a/ext/calendar/jewish.c +++ b/ext/calendar/jewish.c @@ -86,7 +86,7 @@ * 4 Tevet 29 29 29 29 29 29 * 5 Shevat 30 30 30 30 30 30 * 6 Adar I -- -- -- 30 30 30 (optional) - * 7 Adar II 29 29 29 29 29 29 + * 7 Adar (II) 29 29 29 29 29 29 * 8 Nisan 30 30 30 30 30 30 * 9 Iyyar 29 29 29 29 29 29 * 10 Sivan 30 30 30 30 30 30 @@ -286,7 +286,7 @@ #define AM3_11_20 ((9 * HALAKIM_PER_HOUR) + 204) #define AM9_32_43 ((15 * HALAKIM_PER_HOUR) + 589) -static int monthsPerYear[19] = +int monthsPerYear[19] = { 12, 12, 13, 12, 12, 13, 12, 13, 12, 12, 13, 12, 12, 13, 12, 12, 13, 12, 13 }; diff --git a/ext/calendar/sdncal.h b/ext/calendar/sdncal.h index 81328d1369cf5..c0463c80d45e6 100644 --- a/ext/calendar/sdncal.h +++ b/ext/calendar/sdncal.h @@ -79,7 +79,10 @@ long int JulianToSdn(int year, int month, int day); void SdnToJewish(long int sdn, int *pYear, int *pMonth, int *pDay); long int JewishToSdn(int year, int month, int day); extern char *JewishMonthName[14]; +extern char *JewishMonthNameLeap[14]; extern char *JewishMonthHebName[14]; +extern char *JewishMonthHebNameLeap[14]; +extern int monthsPerYear[19]; /* French republic calendar conversions. */ void SdnToFrench(long int sdn, int *pYear, int *pMonth, int *pDay); diff --git a/ext/calendar/tests/jdmonthname.phpt b/ext/calendar/tests/jdmonthname.phpt index d05d3c595efca..207d320162b7b 100644 --- a/ext/calendar/tests/jdmonthname.phpt +++ b/ext/calendar/tests/jdmonthname.phpt @@ -178,7 +178,7 @@ Heshvan Kislev Tevet Shevat -AdarI +Adar Nisan Iyyar Sivan @@ -279,7 +279,7 @@ Heshvan Kislev Tevet Shevat -AdarI +Adar Nisan Iyyar Sivan diff --git a/ext/calendar/tests/jdtojewish.phpt b/ext/calendar/tests/jdtojewish.phpt index 484b95749cca9..bc0ecbdd88ec2 100644 --- a/ext/calendar/tests/jdtojewish.phpt +++ b/ext/calendar/tests/jdtojewish.phpt @@ -14,10 +14,11 @@ var_dump(jdtojewish(gregoriantojd(10,28,2002))."\r\n". jdtojewish(gregoriantojd(10,8,2002),true, CAL_JEWISH_ADD_GERESHAYIM)."\r\n". jdtojewish(gregoriantojd(10,8,2002),true, CAL_JEWISH_ADD_GERESHAYIM+CAL_JEWISH_ADD_ALAFIM_GERESH)."\r\n". jdtojewish(gregoriantojd(10,8,2002),true, CAL_JEWISH_ADD_GERESHAYIM+CAL_JEWISH_ADD_ALAFIM)."\r\n". - jdtojewish(gregoriantojd(10,8,2002),true, CAL_JEWISH_ADD_GERESHAYIM+CAL_JEWISH_ADD_ALAFIM+CAL_JEWISH_ADD_ALAFIM_GERESH)."\r\n"); + jdtojewish(gregoriantojd(10,8,2002),true, CAL_JEWISH_ADD_GERESHAYIM+CAL_JEWISH_ADD_ALAFIM+CAL_JEWISH_ADD_ALAFIM_GERESH)."\r\n". + jdtojewish(gregoriantojd(3,10,2007))."\r\n"); ?> ---EXPECT-- -string(184) "2/22/5763 +--EXPECTF-- +string(%d) "2/22/5763 כב חשון התשסג כב חשון ה'תשסג כב חשון ה אלפים תשסג @@ -27,4 +28,5 @@ string(184) "2/22/5763 ב' חשון ה'תשס"ג ב' חשון ה אלפים תשס"ג ב' חשון ה' אלפים תשס"ג +7/20/5767 " From 3ebd425264f84b3cdf826a519a820ed39f375381 Mon Sep 17 00:00:00 2001 From: Stanislav Malyshev Date: Tue, 7 Aug 2012 01:17:17 -0700 Subject: [PATCH 5/5] text fixes from emosenkis --- ext/calendar/jewish.c | 8 ++++---- ext/calendar/tests/cal_info.phpt | 8 ++++---- ext/calendar/tests/jdmonthname.phpt | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ext/calendar/jewish.c b/ext/calendar/jewish.c index a5849a7d7690c..9e5b0beced7ab 100644 --- a/ext/calendar/jewish.c +++ b/ext/calendar/jewish.c @@ -306,8 +306,8 @@ char *JewishMonthNameLeap[14] = "Kislev", "Tevet", "Shevat", - "AdarI", - "AdarII", + "Adar I", + "Adar II", "Nisan", "Iyyar", "Sivan", @@ -344,8 +344,8 @@ char *JewishMonthHebNameLeap[14] = "כסלו", "טבת", "שבט", - "'אדר ר", - "'אדר ב", + "אדר א'", + "אדר ב'", "ניסן", "אייר", "סיון", diff --git a/ext/calendar/tests/cal_info.phpt b/ext/calendar/tests/cal_info.phpt index 2e3e612925c07..7edb4ce67ca79 100644 --- a/ext/calendar/tests/cal_info.phpt +++ b/ext/calendar/tests/cal_info.phpt @@ -100,8 +100,8 @@ Array [3] => Kislev [4] => Tevet [5] => Shevat - [6] => AdarI - [7] => AdarII + [6] => Adar I + [7] => Adar II [8] => Nisan [9] => Iyyar [10] => Sivan @@ -117,8 +117,8 @@ Array [3] => Kislev [4] => Tevet [5] => Shevat - [6] => AdarI - [7] => AdarII + [6] => Adar I + [7] => Adar II [8] => Nisan [9] => Iyyar [10] => Sivan diff --git a/ext/calendar/tests/jdmonthname.phpt b/ext/calendar/tests/jdmonthname.phpt index 207d320162b7b..07ed1161b1753 100644 --- a/ext/calendar/tests/jdmonthname.phpt +++ b/ext/calendar/tests/jdmonthname.phpt @@ -75,8 +75,8 @@ December --- mode 4 --- Tevet Shevat -AdarI -AdarII +Adar I +Adar II Nisan Iyyar Sivan