Back to index

php5  5.3.10
Functions
easter.c File Reference
#include "php.h"
#include "php_calendar.h"
#include "sdncal.h"
#include <time.h>

Go to the source code of this file.

Functions

static void _cal_easter (INTERNAL_FUNCTION_PARAMETERS, int gm)
 PHP_FUNCTION (easter_date)
 PHP_FUNCTION (easter_days)

Function Documentation

static void _cal_easter ( INTERNAL_FUNCTION_PARAMETERS  ,
int  gm 
) [static]

Definition at line 27 of file easter.c.

{

       /* based on code by Simon Kershaw, <webmaster@ely.anglican.org> */

       struct tm te;
       long year, golden, solar, lunar, pfm, dom, tmp, easter;
       long method = CAL_EASTER_DEFAULT;

       /* Default to the current year if year parameter is not given */
       {
              time_t a;
              struct tm b, *res;
              time(&a);
              res = php_localtime_r(&a, &b);
              if (!res) {
                     year = 1900;
              } else {
                     year = 1900 + b.tm_year;
              }
       }

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
              "|ll", &year, &method) == FAILURE) {
                     return;
       }
 
       if (gm && (year<1970 || year>2037)) {                          /* out of range for timestamps */
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "This function is only valid for years between 1970 and 2037 inclusive");
              RETURN_FALSE;
       }

       golden = (year % 19) + 1;                               /* the Golden number */

       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;
              }

              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;
              }

               Z_LVAL_P(return_value) = mktime(&te);
       } else {                                                /* return the days after March 21 */      
               Z_LVAL_P(return_value) = easter;
       }

        Z_TYPE_P(return_value) = IS_LONG;

}

Here is the call graph for this function:

Here is the caller graph for this function:

PHP_FUNCTION ( easter_date  )

Definition at line 126 of file easter.c.

Here is the call graph for this function:

PHP_FUNCTION ( easter_days  )

Definition at line 134 of file easter.c.

Here is the call graph for this function: