]> granicus.if.org Git - php/commitdiff
Add an option to calculate easter dates based on the Gregorian calendar
authorMarko Karppinen <markonen@php.net>
Sun, 12 May 2002 15:06:04 +0000 (15:06 +0000)
committerMarko Karppinen <markonen@php.net>
Sun, 12 May 2002 15:06:04 +0000 (15:06 +0000)
during the years 1582-1752. Earlier this was only possible from
1753 onwards. Use the optional parameter CAL_EASTER_ROMAN with
easter_days() to enable this. This is a fix for bug #12766.
# As you can see, my Sundays are *so* busy...

ext/calendar/calendar.c
ext/calendar/easter.c
ext/calendar/php_calendar.h

index 000918d7f143d48914dd34fb06cc3f4a5c746737..d5a346c056f77836422fe3777312f22891b8ff92 100644 (file)
@@ -127,7 +127,11 @@ PHP_MINIT_FUNCTION(calendar)
        REGISTER_LONG_CONSTANT("CAL_MONTH_JULIAN_LONG",         CAL_MONTH_JULIAN_LONG, CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("CAL_MONTH_JEWISH",                      CAL_MONTH_JEWISH, CONST_CS|CONST_PERSISTENT);
        REGISTER_LONG_CONSTANT("CAL_MONTH_FRENCH",                      CAL_MONTH_FRENCH, CONST_CS|CONST_PERSISTENT);
-
+       /* constants for easter calculation */
+       REGISTER_LONG_CONSTANT("CAL_EASTER_DEFAULT",                    CAL_EASTER_DEFAULT, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("CAL_EASTER_ROMAN",                              CAL_EASTER_ROMAN, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("CAL_EASTER_ALWAYS_GREGORIAN",   CAL_EASTER_ALWAYS_GREGORIAN, CONST_CS | CONST_PERSISTENT);
+       REGISTER_LONG_CONSTANT("CAL_EASTER_ALWAYS_JULIAN",              CAL_EASTER_ALWAYS_JULIAN, CONST_CS | CONST_PERSISTENT);
        return SUCCESS;
 }
 
index 0a2121e7517043a5db662c02531d1b53b83e8f52..baf4919cc051b91b3203be392a1e57276b020de9 100644 (file)
@@ -29,36 +29,27 @@ static void _cal_easter(INTERNAL_FUNCTION_PARAMETERS, int gm)
 
        /* based on code by Simon Kershaw, <webmaster@ely.anglican.org> */
 
-       pval *year_arg;
        struct tm *ta, te;
        time_t the_time;
        long year, golden, solar, lunar, pfm, dom, tmp, easter;
+       long method = CAL_EASTER_DEFAULT;
 
-       switch(ZEND_NUM_ARGS()) {
-       case 0:
-               the_time = time(NULL);
-               ta = localtime(&the_time);
-               year = ta->tm_year + 1900;
-               break;
-       case 1:
-               if (getParameters(ht, 1, &year_arg) == FAILURE) {
-                       WRONG_PARAM_COUNT;
-               }
-               convert_to_long(year_arg);
-               year = Z_LVAL_P(year_arg);
-               break;
-       default:
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
+               "l|l", &year, &method) == FAILURE) {
+                       return;
        }
  
        if (gm && (year<1970 || year>2037)) {                           /* out of range for timestamps */
-               php3_error(E_WARNING, "easter_date() is only valid for years between 1970 and 2037 inclusive");
+               php_error(E_WARNING, "easter_date() is only valid for years between 1970 and 2037 inclusive");
                RETURN_FALSE;
        }
 
        golden = (year % 19) + 1;                                       /* the Golden number */
 
-       if ( year <= 1752 ) {                                           /* JULIAN CALENDAR */
+       if ((year <= 1582 && method != CAL_EASTER_ALWAYS_GREGORIAN) ||
+           (year >= 1583 && year <= 1752 && method != CAL_EASTER_ROMAN && method != CAL_EASTER_ALWAYS_GREGORIAN) ||
+            method == CAL_EASTER_ALWAYS_JULIAN) {              /* JULIAN CALENDAR */
+            
                dom = (year + (year/4) + 5) % 7;                        /* the "Dominical number" - finding a Sunday */
                if (dom < 0) {
                        dom += 7;
index 73bc96aede6db4c9da664fc09462fd515ac2c787..79c9edf73c321859a51dcacc8b929a4cadf402e3 100644 (file)
@@ -32,4 +32,19 @@ PHP_FUNCTION(cal_info);
 
 #define phpext_calendar_ptr calendar_module_ptr
 
+/*
+ * Specifying the easter calculation method
+ * 
+ * DEFAULT is Anglican, ie. use Julian calendar before 1753
+ * and Gregorian after that. With ROMAN, the cutoff year is 1582.
+ * ALWAYS_GREGORIAN and ALWAYS_JULIAN force the calendar
+ * regardless of date.
+ *
+ */
+#define CAL_EASTER_DEFAULT                     0
+#define CAL_EASTER_ROMAN                       1
+#define CAL_EASTER_ALWAYS_GREGORIAN    2
+#define CAL_EASTER_ALWAYS_JULIAN       3
+
 #endif