mirror of
https://github.com/php/php-src.git
synced 2024-11-24 10:24:11 +08:00
- Added an aditional parameter to the jdtojewish() function which makes
the function return the symbolic hebrew name. (Patch by Moshe Doron <mosdoron@netvision.net.il>) @- Added an aditional parameter to the jdtojewish() function which makes @ the function return the symbolic hebrew name. (Moshe Doron, Derick)
This commit is contained in:
parent
bfdb85d1f0
commit
0998fcd804
@ -33,6 +33,8 @@
|
||||
#include "php_calendar.h"
|
||||
#include "sdncal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
function_entry calendar_functions[] = {
|
||||
PHP_FE(jdtogregorian, NULL)
|
||||
PHP_FE(gregoriantojd, NULL)
|
||||
@ -108,6 +110,9 @@ enum { CAL_DOW_DAYNO, CAL_DOW_SHORT, CAL_DOW_LONG };
|
||||
enum { CAL_MONTH_GREGORIAN_SHORT, CAL_MONTH_GREGORIAN_LONG,
|
||||
CAL_MONTH_JULIAN_SHORT, CAL_MONTH_JULIAN_LONG, CAL_MONTH_JEWISH,
|
||||
CAL_MONTH_FRENCH };
|
||||
|
||||
/* for heb_number_to_chars */
|
||||
char alef_bet[25] = "0àáâãäåæçèéëìîðñòôö÷øùú";
|
||||
|
||||
PHP_MINIT_FUNCTION(calendar)
|
||||
{
|
||||
@ -371,24 +376,111 @@ PHP_FUNCTION(jdtogregorian)
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
/*
|
||||
caution: the hebrew format product non unique result.
|
||||
for example both: year '5' and year '5000' product 'ä'.
|
||||
use the numeric one for calculations.
|
||||
*/
|
||||
char* heb_number_to_chars(int n) {
|
||||
char *p, *old, *ret;
|
||||
|
||||
p = emalloc(10);
|
||||
old = p;
|
||||
|
||||
/*
|
||||
prevents the option breaking the jewish beliefs, and some other
|
||||
critical resources ;)
|
||||
*/
|
||||
if (n > 9999 || n < 1) return NULL;
|
||||
|
||||
/* alafim case */
|
||||
if (n / 1000) {
|
||||
*p = alef_bet[n / 1000];
|
||||
p++;
|
||||
n = n % 1000;
|
||||
}
|
||||
|
||||
/* taf-taf case */
|
||||
while (n >= 400) {
|
||||
*p = alef_bet[22];
|
||||
p++;
|
||||
n-=400;
|
||||
}
|
||||
|
||||
/* meot case */
|
||||
if (n >= 100) {
|
||||
*p = alef_bet[18+n/100];
|
||||
p++;
|
||||
n = n % 100;
|
||||
}
|
||||
|
||||
/* tet-vav tet-zain case */
|
||||
if (n == 15 || n == 16) {
|
||||
*p = alef_bet[9];
|
||||
p++;
|
||||
*p = alef_bet[n-9];
|
||||
p++;
|
||||
} else {
|
||||
/* asarot case */
|
||||
if (n >= 10) {
|
||||
*p = alef_bet[9+n/10];
|
||||
p++;
|
||||
n = n % 10;
|
||||
}
|
||||
|
||||
/* yeihot case */
|
||||
if (n > 0) {
|
||||
*p = alef_bet[n];
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
*p = '\0';
|
||||
ret = emalloc((int) (p - old) + 1);
|
||||
strncpy(ret, old, (int) (p - old) + 1);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* {{{ proto string jdtojewish(int juliandaycount)
|
||||
Converts a julian day count to a jewish calendar date */
|
||||
PHP_FUNCTION(jdtojewish)
|
||||
{
|
||||
pval **julday;
|
||||
long julday, fl;
|
||||
int year, month, day;
|
||||
char date[10];
|
||||
|
||||
if (zend_get_parameters_ex(1, &julday) != SUCCESS) {
|
||||
char date[10], hebdate[25];
|
||||
|
||||
if (ZEND_NUM_ARGS() == 1) {
|
||||
if (zend_parse_parameters(1 TSRMLS_CC,"l", &julday) != SUCCESS) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
fl=0;
|
||||
} else if (ZEND_NUM_ARGS() == 2) {
|
||||
if (zend_parse_parameters(2 TSRMLS_CC,"ll", &julday, &fl) != SUCCESS) {
|
||||
RETURN_FALSE;
|
||||
}
|
||||
} else {
|
||||
WRONG_PARAM_COUNT;
|
||||
}
|
||||
|
||||
convert_to_long_ex(julday);
|
||||
|
||||
SdnToJewish(Z_LVAL_PP(julday), &year, &month, &day);
|
||||
sprintf(date, "%i/%i/%i", month, day, year);
|
||||
|
||||
RETURN_STRING(date, 1);
|
||||
SdnToJewish(julday, &year, &month, &day);
|
||||
if(!fl) {
|
||||
sprintf(date, "%i/%i/%i", month, day, year);
|
||||
RETURN_STRING(date, 1);
|
||||
} else {
|
||||
if (year <= 0 || year > 9999) {
|
||||
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Out of range year.");
|
||||
RETURN_FALSE;
|
||||
}
|
||||
|
||||
sprintf(hebdate, "%s %s %s", \
|
||||
heb_number_to_chars(day), \
|
||||
JewishMonthHebName[month], \
|
||||
heb_number_to_chars(year));
|
||||
|
||||
RETURN_STRING(hebdate, 1);
|
||||
|
||||
}
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
@ -311,6 +311,24 @@ char *JewishMonthName[14] =
|
||||
"Elul"
|
||||
};
|
||||
|
||||
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
|
||||
|
@ -79,6 +79,7 @@ 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 *JewishMonthHebName[14];
|
||||
|
||||
/* French republic calendar conversions. */
|
||||
void SdnToFrench(long int sdn, int *pYear, int *pMonth, int *pDay);
|
||||
@ -93,4 +94,4 @@ int DayOfWeek(long int sdn);
|
||||
extern char *DayNameShort[7];
|
||||
extern char *DayNameLong[7];
|
||||
|
||||
#endif /* SDNCAL_H */
|
||||
#endif /* SDNCAL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user