#include <stdio.h>
+ZEND_DECLARE_MODULE_GLOBALS(calendar);
+
/* {{{ arginfo */
static
ZEND_BEGIN_ARG_INFO_EX(arginfo_unixtojd, 0, 0, 0)
{NULL, NULL, NULL}
};
+static PHP_GINIT_FUNCTION(calendar)
+{
+ if (zend_set_converter_encoding(&(calendar_globals->iso_8859_8_conv), "iso-8859-8") == FAILURE) {
+ php_error(E_CORE_WARNING, "Unable to instatiate iso-8859-8 converter for calendar extension, will be unable to produce hebrew dates in unicode mode");
+ calendar_globals = NULL;
+ }
+}
+
+static PHP_GSHUTDOWN_FUNCTION(calendar)
+{
+ if (calendar_globals->iso_8859_8_conv) {
+ ucnv_close(calendar_globals->iso_8859_8_conv);
+ }
+}
zend_module_entry calendar_module_entry = {
STANDARD_MODULE_HEADER,
NULL,
PHP_MINFO(calendar),
NO_VERSION_YET,
- STANDARD_MODULE_PROPERTIES,
+ PHP_MODULE_GLOBALS(calendar),
+ PHP_GINIT(calendar),
+ PHP_GSHUTDOWN(calendar),
+ NULL,
+ STANDARD_MODULE_PROPERTIES_EX,
};
#ifdef COMPILE_DL_CALENDAR
php_info_print_table_end();
}
-static void _php_cal_info(int cal, zval **ret)
+static void _php_cal_info(int cal, zval **ret TSRMLS_DC)
{
zval *months, *smonths;
int i;
array_init(smonths);
for (i = 1; i <= calendar->num_months; i++) {
- add_index_string(months, i, calendar->month_name_long[i], 1);
- add_index_string(smonths, i, calendar->month_name_short[i], 1);
- }
- add_assoc_zval(*ret, "months", months);
- add_assoc_zval(*ret, "abbrevmonths", smonths);
- add_assoc_long(*ret, "maxdaysinmonth", calendar->max_days_in_month);
- add_assoc_string(*ret, "calname", calendar->name, 1);
- add_assoc_string(*ret, "calsymbol", calendar->symbol, 1);
+ add_index_ascii_string(months, i, calendar->month_name_long[i], ZSTR_DUPLICATE);
+ add_index_ascii_string(smonths, i, calendar->month_name_short[i], ZSTR_DUPLICATE);
+ }
+
+ add_ascii_assoc_zval(*ret, "months", months);
+ add_ascii_assoc_zval(*ret, "abbrevmonths", smonths);
+ add_ascii_assoc_long(*ret, "maxdaysinmonth", calendar->max_days_in_month);
+ add_ascii_assoc_ascii_string(*ret, "calname", calendar->name, 1);
+ add_ascii_assoc_ascii_string(*ret, "calsymbol", calendar->symbol, 1);
}
-/* {{{ proto array cal_info([int calendar])
+/* {{{ proto array cal_info([int calendar]) U
Returns information about a particular calendar */
PHP_FUNCTION(cal_info)
{
long cal = -1;
-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &cal) == FAILURE) {
RETURN_FALSE;
for (i = 0; i < CAL_NUM_CALS; i++) {
MAKE_STD_ZVAL(val);
- _php_cal_info(i, &val);
+ _php_cal_info(i, &val TSRMLS_CC);
add_index_zval(return_value, i, val);
}
return;
RETURN_FALSE;
}
- _php_cal_info(cal, &return_value);
+ _php_cal_info(cal, &return_value TSRMLS_CC);
}
/* }}} */
-/* {{{ proto int cal_days_in_month(int calendar, int month, int year)
+/* {{{ proto int cal_days_in_month(int calendar, int month, int year) U
Returns the number of days in a month for a given year and calendar */
PHP_FUNCTION(cal_days_in_month)
{
sdn_next = calendar->to_jd(year, 1 + month, 1);
if (sdn_next == 0) {
-/* if invalid, try first month of the next year... */
+ /* if invalid, try first month of the next year... */
sdn_next = calendar->to_jd(year + 1, 1, 1);
}
}
/* }}} */
-/* {{{ proto int cal_to_jd(int calendar, int month, int day, int year)
+/* {{{ proto int cal_to_jd(int calendar, int month, int day, int year) U
Converts from a supported calendar to Julian Day Count */
PHP_FUNCTION(cal_to_jd)
{
}
/* }}} */
-/* {{{ proto array cal_from_jd(int jd, int calendar)
+/* {{{ proto array cal_from_jd(int jd, int calendar) U
Converts from Julian Day Count to a supported calendar and return extended information */
PHP_FUNCTION(cal_from_jd)
{
add_assoc_long(return_value, "day", day);
add_assoc_long(return_value, "year", year);
-/* day of week */
+ /* day of week */
dow = DayOfWeek(jd);
- add_assoc_long(return_value, "dow", dow);
- 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);
+ add_ascii_assoc_long(return_value, "dow", dow);
+ add_ascii_assoc_ascii_string(return_value, "abbrevdayname", DayNameShort[dow], 1);
+ add_ascii_assoc_ascii_string(return_value, "dayname", DayNameLong[dow], 1);
+
+ /* month name */
+ add_ascii_assoc_ascii_string(return_value, "abbrevmonth", calendar->month_name_short[month], 1);
+ add_ascii_assoc_ascii_string(return_value, "monthname", calendar->month_name_long[month], 1);
}
/* }}} */
-/* {{{ proto string jdtogregorian(int juliandaycount)
+/* {{{ proto string jdtogregorian(int juliandaycount) U
Converts a julian day count to a gregorian calendar date */
PHP_FUNCTION(jdtogregorian)
{
SdnToGregorian(julday, &year, &month, &day);
snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
- RETURN_STRING(date, 1);
+ RETURN_ASCII_STRING(date, ZSTR_DUPLICATE);
}
/* }}} */
-/* {{{ proto int gregoriantojd(int month, int day, int year)
+/* {{{ proto int gregoriantojd(int month, int day, int year) U
Converts a gregorian calendar date to julian day count */
PHP_FUNCTION(gregoriantojd)
{
}
/* }}} */
-/* {{{ proto string jdtojulian(int juliandaycount)
+/* {{{ proto string jdtojulian(int juliandaycount) U
Convert a julian day count to a julian calendar date */
PHP_FUNCTION(jdtojulian)
{
SdnToJulian(julday, &year, &month, &day);
snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
- RETURN_STRING(date, 1);
+ RETURN_ASCII_STRING(date, ZSTR_DUPLICATE);
}
/* }}} */
-/* {{{ proto int juliantojd(int month, int day, int year)
+/* {{{ proto int juliantojd(int month, int day, int year) U
Converts a julian calendar date to julian day count */
PHP_FUNCTION(juliantojd)
{
}
/* }}} */
-/* {{{ proto string jdtojewish(int juliandaycount [, bool hebrew [, int fl]])
+/* {{{ proto string jdtojewish(int juliandaycount [, bool hebrew [, int fl]]) U
Converts a julian day count to a jewish calendar date */
PHP_FUNCTION(jdtojewish)
{
efree(yearp);
}
- RETURN_STRING(hebdate, 1);
-
+ if (UG(unicode) && CALENDAR_G(iso_8859_8_conv)) {
+ RETURN_U_STRING(CALENDAR_G(iso_8859_8_conv), hebdate, ZSTR_DUPLICATE);
+ } else {
+ RETURN_STRING(hebdate, 1);
+ }
}
}
/* }}} */
-/* {{{ proto int jewishtojd(int month, int day, int year)
+/* {{{ proto int jewishtojd(int month, int day, int year) U
Converts a jewish calendar date to a julian day count */
PHP_FUNCTION(jewishtojd)
{
}
/* }}} */
-/* {{{ proto string jdtofrench(int juliandaycount)
+/* {{{ proto string jdtofrench(int juliandaycount) U
Converts a julian day count to a french republic calendar date */
PHP_FUNCTION(jdtofrench)
{
SdnToFrench(julday, &year, &month, &day);
snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
- RETURN_STRING(date, 1);
+ RETURN_ASCII_STRING(date, ZSTR_DUPLICATE);
}
/* }}} */
-/* {{{ proto int frenchtojd(int month, int day, int year)
+/* {{{ proto int frenchtojd(int month, int day, int year) U
Converts a french republic calendar date to julian day count */
PHP_FUNCTION(frenchtojd)
{
}
/* }}} */
-/* {{{ proto mixed jddayofweek(int juliandaycount [, int mode])
+/* {{{ proto mixed jddayofweek(int juliandaycount [, int mode]) U
Returns name or number of day of week from julian day count */
PHP_FUNCTION(jddayofweek)
{
switch (mode) {
case CAL_DOW_SHORT:
- RETURN_STRING(daynamel, 1);
+ RETURN_ASCII_STRING(daynamel, ZSTR_DUPLICATE);
break;
case CAL_DOW_LONG:
- RETURN_STRING(daynames, 1);
+ RETURN_ASCII_STRING(daynames, ZSTR_DUPLICATE);
break;
case CAL_DOW_DAYNO:
default:
}
/* }}} */
-/* {{{ proto string jdmonthname(int juliandaycount, int mode)
+/* {{{ proto string jdmonthname(int juliandaycount, int mode) U
Returns name of month for julian day count */
PHP_FUNCTION(jdmonthname)
{
case CAL_MONTH_JEWISH: /* jewish month */
SdnToJewish(julday, &year, &month, &day);
monthname = JewishMonthName[month];
+ if (UG(unicode) && CALENDAR_G(iso_8859_8_conv)) {
+ RETURN_U_STRING(CALENDAR_G(iso_8859_8_conv), monthname, ZSTR_DUPLICATE);
+ } else {
+ RETURN_STRING(monthname, 1);
+ }
break;
case CAL_MONTH_FRENCH: /* french month */
SdnToFrench(julday, &year, &month, &day);
break;
}
- RETURN_STRING(monthname, 1);
+ RETURN_ASCII_STRING(monthname, ZSTR_DUPLICATE);
}
/* }}} */