CVS update: php3/functions

From: Date: Wed, 02 Jun 1999 23:53:17 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-6484@lists.php.net to get a copy of this message
Date: Wednesday June 2, 1999 @ 19:53 Author: cmv Update of /repository/php3/functions In directory php:/tmp/cvs-serv6946/functions Modified Files: basic_functions.c datetime.c datetime.h Log Message: added easter_date() and easter_days() functions Index: php3/functions/basic_functions.c diff -u php3/functions/basic_functions.c:1.263 php3/functions/basic_functions.c:1.264 --- php3/functions/basic_functions.c:1.263 Sat May 22 18:34:56 1999 +++ php3/functions/basic_functions.c Wed Jun 2 19:53:16 1999 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.263 1999/05/22 22:34:56 sas Exp $ */ +/* $Id: basic_functions.c,v 1.264 1999/06/02 23:53:16 cmv Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif @@ -122,6 +122,8 @@ {"sizeof", php3_count, first_arg_allow_ref}, {"count", php3_count, first_arg_allow_ref}, {"time", php3_time, NULL}, + {"easter_date", php3_easter_date, NULL}, + {"easter_days", php3_easter_days, NULL}, {"mktime", php3_mktime, NULL}, {"gmmktime", php3_gmmktime, NULL}, #if HAVE_STRFTIME Index: php3/functions/datetime.c diff -u php3/functions/datetime.c:1.52 php3/functions/datetime.c:1.53 --- php3/functions/datetime.c:1.52 Wed Jun 2 13:22:30 1999 +++ php3/functions/datetime.c Wed Jun 2 19:53:17 1999 @@ -30,7 +30,7 @@ */ -/* $Id: datetime.c,v 1.52 1999/06/02 17:22:30 cmv Exp $ */ +/* $Id: datetime.c,v 1.53 1999/06/02 23:53:17 cmv Exp $ */ #ifdef THREAD_SAFE @@ -156,6 +156,118 @@ _php3_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } /* }}} */ + + +void _php3_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; + int year, golden, solar, lunar, pfm, dom, tmp, easter; + + switch(ARG_COUNT(ht)) { + 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 = year_arg->value.lval; + break; + default: + WRONG_PARAM_COUNT; + } + + 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"); + RETURN_FALSE; + } + + golden = (year % 19) + 1; /* the Golden number */ + + if ( year <= 1752 ) { /* JULIAN CALENDAR */ + dom = (year + (year/4) + 5) % 7; /* the "Dominical number" - finding a Sunday */ + if (dom < 0) { + dom += 7; + } + + pfm = (3 - (11*golden) - 7) % 30; /* uncorrected date of the Paschal full moon */ + if (pfm < 0) { + pfm += 30; + } + } else { /* GREGORIAN CALENDAR */ + dom = (year + (year/4) - (year/100) + (year/400)) % 7; /* the "Domincal number" */ + if (dom < 0) { + dom += 7; + } + + solar = (year-1600)/100 - (year-1600)/400; /* the solar and lunar corrections */ + lunar = (((year-1400) / 100) * 8) / 25; + + pfm = (3 - (11*golden) + solar - lunar) % 30; /* uncorrected date of the Paschal full moon */ + if (pfm < 0) { + pfm += 30; + } + } + + if ((pfm == 29) || (pfm == 28 && golden > 11)) { /* corrected date of the Paschal full moon */ + pfm--; /* - days after 21st March */ + } + + tmp = (4-pfm-dom) % 7; + if (tmp < 0) { + tmp += 7; + } + + easter = pfm + tmp + 1; /* Easter as the number of days after 21st March */ + + if (gm) { /* return a timestamp */ + te.tm_isdst = -1; + te.tm_year = year-1900; + te.tm_sec = 0; + te.tm_min = 0; + te.tm_hour = 0; + + if (easter < 11) { + te.tm_mon = 2; /* March */ + te.tm_mday = easter+21; + } else { + te.tm_mon = 3; /* April */ + te.tm_mday = easter-10; + } + + return_value->value.lval = mktime(&te); + } else { /* return the days after March 21 */ + return_value->value.lval = easter; + } + + return_value->type = IS_LONG; + +} + +/* {{{ proto int easter_date([int year]) + Return the timestamp of midnight on Easter of a given year (defaults to current year) */ +void php3_easter_date(INTERNAL_FUNCTION_PARAMETERS) +{ + _php3_easter(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); +} +/* }}} */ + +/* {{{ proto int easter_days([int year]) + Return the number of days after March 21 that Easter falls on for a given year (defaults to current year) */ +void php3_easter_days(INTERNAL_FUNCTION_PARAMETERS) +{ + _php3_easter(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); +} +/* }}} */ + static void _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm) Index: php3/functions/datetime.h diff -u php3/functions/datetime.h:1.12 php3/functions/datetime.h:1.13 --- php3/functions/datetime.h:1.12 Fri Jan 1 12:59:08 1999 +++ php3/functions/datetime.h Wed Jun 2 19:53:17 1999 @@ -29,13 +29,15 @@ */ -/* $Id: datetime.h,v 1.12 1999/01/01 17:59:08 zeev Exp $ */ +/* $Id: datetime.h,v 1.13 1999/06/02 23:53:17 cmv Exp $ */ #ifndef _DATETIME_H #define _DATETIME_H extern void php3_time(INTERNAL_FUNCTION_PARAMETERS); extern void php3_mktime(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_easter_date(INTERNAL_FUNCTION_PARAMETERS); +extern void php3_easter_days(INTERNAL_FUNCTION_PARAMETERS); extern void php3_gmmktime(INTERNAL_FUNCTION_PARAMETERS); extern void php3_date(INTERNAL_FUNCTION_PARAMETERS); extern void php3_gmdate(INTERNAL_FUNCTION_PARAMETERS);

« previous php.dev (#6484) next »