cvs: php4 /ext/calendar calendar.c easter.c php_calendar.h

From: Date: Sun, 12 May 2002 15:06:05 +0000
Subject: cvs: php4 /ext/calendar calendar.c easter.c php_calendar.h
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-11866@lists.php.net to get a copy of this message
markonen Sun May 12 11:06:05 2002 EDT Modified files: /php4/ext/calendar calendar.c easter.c php_calendar.h Log: Add an option to calculate easter dates based on the Gregorian calendar 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... Index: php4/ext/calendar/calendar.c diff -u php4/ext/calendar/calendar.c:1.24 php4/ext/calendar/calendar.c:1.25 --- php4/ext/calendar/calendar.c:1.24 Tue Dec 11 10:28:54 2001 +++ php4/ext/calendar/calendar.c Sun May 12 11:06:04 2002 @@ -18,7 +18,7 @@ | Wez Furlong <wez@thebrainroom.com> | +----------------------------------------------------------------------+ */ -/* $Id: calendar.c,v 1.24 2001/12/11 15:28:54 sebastian Exp $ */ +/* $Id: calendar.c,v 1.25 2002/05/12 15:06:04 markonen Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -127,7 +127,11 @@ 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: php4/ext/calendar/easter.c diff -u php4/ext/calendar/easter.c:1.7 php4/ext/calendar/easter.c:1.8 --- php4/ext/calendar/easter.c:1.7 Tue Dec 11 10:28:54 2001 +++ php4/ext/calendar/easter.c Sun May 12 11:06:04 2002 @@ -29,36 +29,27 @@ /* 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: php4/ext/calendar/php_calendar.h diff -u php4/ext/calendar/php_calendar.h:1.5 php4/ext/calendar/php_calendar.h:1.6 --- php4/ext/calendar/php_calendar.h:1.5 Wed Jul 4 06:12:45 2001 +++ php4/ext/calendar/php_calendar.h Sun May 12 11:06:04 2002 @@ -32,4 +32,19 @@ #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

« previous php.cvs (#11866) next »