]> granicus.if.org Git - php/commitdiff
- Added an aditional parameter to the jdtojewish() function which makes
authorDerick Rethans <derick@php.net>
Thu, 31 Oct 2002 09:16:23 +0000 (09:16 +0000)
committerDerick Rethans <derick@php.net>
Thu, 31 Oct 2002 09:16:23 +0000 (09:16 +0000)
  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)

ext/calendar/calendar.c
ext/calendar/jewish.c
ext/calendar/sdncal.h

index 5bfeabb28a38d5bd7e787e841cdb1ac784064ea7..b9e4406328ad7ec929d35b525cd4424299512082 100644 (file)
@@ -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);
+               
+       }
 }
 /* }}} */
 
index 504f3c2d939a373f11dbca3346a2d620f4c0a629..b83f4fa04f899aa1404ff1525addc718a3a22b5d 100644 (file)
@@ -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
index 6621d136823812504d3afb825c9e24236d2d76f8..81328d1369cf5e9cb5eb9e891d7e998144d9033d 100644 (file)
@@ -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 */