summaryrefslogtreecommitdiff
path: root/ext/calendar
diff options
context:
space:
mode:
authorMarko Karppinen <markonen@php.net>2002-05-12 15:06:04 +0000
committerMarko Karppinen <markonen@php.net>2002-05-12 15:06:04 +0000
commit554b7684edae7b1173096a01c83c68998c026c3b (patch)
treea8781bd206a3477caf4d37783a705f168332d208 /ext/calendar
parentb3de60dbf0ced6506497382642d75cfb977980b7 (diff)
downloadphp-git-554b7684edae7b1173096a01c83c68998c026c3b.tar.gz
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...
Diffstat (limited to 'ext/calendar')
-rw-r--r--ext/calendar/calendar.c6
-rw-r--r--ext/calendar/easter.c27
-rw-r--r--ext/calendar/php_calendar.h15
3 files changed, 29 insertions, 19 deletions
diff --git a/ext/calendar/calendar.c b/ext/calendar/calendar.c
index 000918d7f1..d5a346c056 100644
--- a/ext/calendar/calendar.c
+++ b/ext/calendar/calendar.c
@@ -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;
}
diff --git a/ext/calendar/easter.c b/ext/calendar/easter.c
index 0a2121e751..baf4919cc0 100644
--- a/ext/calendar/easter.c
+++ b/ext/calendar/easter.c
@@ -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;
diff --git a/ext/calendar/php_calendar.h b/ext/calendar/php_calendar.h
index 73bc96aede..79c9edf73c 100644
--- a/ext/calendar/php_calendar.h
+++ b/ext/calendar/php_calendar.h
@@ -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