derick          Thu Oct 31 04:16:23 2002 EDT

  Modified files:              
    /php4/ext/calendar  calendar.c jewish.c sdncal.h 
  Log:
  - Added an aditional parameter to the jdtojewish() function which makes
    the function return the symbolic hebrew name. (Patch by Moshe Doron
    <[EMAIL PROTECTED]>)
  @- Added an aditional parameter to the jdtojewish() function which makes
  @  the function return the symbolic hebrew name. (Moshe Doron, Derick)
  
  
Index: php4/ext/calendar/calendar.c
diff -u php4/ext/calendar/calendar.c:1.26 php4/ext/calendar/calendar.c:1.27
--- php4/ext/calendar/calendar.c:1.26   Thu Sep 19 17:51:34 2002
+++ php4/ext/calendar/calendar.c        Thu Oct 31 04:16:23 2002
@@ -18,7 +18,7 @@
    |          Wez Furlong               <[EMAIL PROTECTED]>            |
    +----------------------------------------------------------------------+
  */
-/* $Id: calendar.c,v 1.26 2002/09/19 21:51:34 cmv Exp $ */
+/* $Id: calendar.c,v 1.27 2002/10/31 09:16:23 derick Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -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_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 @@
 }
 /* }}} */
 
+/*     
+       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: php4/ext/calendar/jewish.c
diff -u php4/ext/calendar/jewish.c:1.4 php4/ext/calendar/jewish.c:1.5
--- php4/ext/calendar/jewish.c:1.4      Sat Feb  2 14:27:33 2002
+++ php4/ext/calendar/jewish.c  Thu Oct 31 04:16:23 2002
@@ -311,6 +311,24 @@
        "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: php4/ext/calendar/sdncal.h
diff -u php4/ext/calendar/sdncal.h:1.2 php4/ext/calendar/sdncal.h:1.3
--- php4/ext/calendar/sdncal.h:1.2      Sun Jul  2 19:46:38 2000
+++ php4/ext/calendar/sdncal.h  Thu Oct 31 04:16:23 2002
@@ -79,6 +79,7 @@
 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 @@
 extern char *DayNameShort[7];
 extern char *DayNameLong[7];
 
-#endif                                                 /* SDNCAL_H */
+#endif /* SDNCAL_H */



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

Reply via email to