Back to index

php5  5.3.10
Defines | Functions | Variables
php_calendar.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define calendar_module_ptr   &calendar_module_entry
#define phpext_calendar_ptr   calendar_module_ptr
#define CAL_EASTER_DEFAULT   0
#define CAL_EASTER_ROMAN   1
#define CAL_EASTER_ALWAYS_GREGORIAN   2
#define CAL_EASTER_ALWAYS_JULIAN   3

Functions

 PHP_MINIT_FUNCTION (calendar)
 PHP_MINFO_FUNCTION (calendar)
 PHP_FUNCTION (jdtogregorian)
 PHP_FUNCTION (gregoriantojd)
 PHP_FUNCTION (jdtojulian)
 PHP_FUNCTION (juliantojd)
 PHP_FUNCTION (jdtojewish)
 PHP_FUNCTION (jewishtojd)
 PHP_FUNCTION (jdtofrench)
 PHP_FUNCTION (frenchtojd)
 PHP_FUNCTION (jddayofweek)
 PHP_FUNCTION (jdmonthname)
 PHP_FUNCTION (easter_days)
 PHP_FUNCTION (easter_date)
 PHP_FUNCTION (unixtojd)
 PHP_FUNCTION (jdtounix)
 PHP_FUNCTION (cal_from_jd)
 PHP_FUNCTION (cal_to_jd)
 PHP_FUNCTION (cal_days_in_month)
 PHP_FUNCTION (cal_info)

Variables

zend_module_entry calendar_module_entry

Define Documentation

Definition at line 45 of file php_calendar.h.

#define CAL_EASTER_ALWAYS_JULIAN   3

Definition at line 46 of file php_calendar.h.

#define CAL_EASTER_DEFAULT   0

Definition at line 43 of file php_calendar.h.

#define CAL_EASTER_ROMAN   1

Definition at line 44 of file php_calendar.h.

Definition at line 5 of file php_calendar.h.

Definition at line 31 of file php_calendar.h.


Function Documentation

PHP_FUNCTION ( jdtogregorian  )

Definition at line 428 of file calendar.c.

{
       long julday;
       int year, month, day;
       char date[16];

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &julday) == FAILURE) {
              RETURN_FALSE;
       }

       SdnToGregorian(julday, &year, &month, &day);
       snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);

       RETURN_STRING(date, 1);
}

Here is the call graph for this function:

PHP_FUNCTION ( gregoriantojd  )

Definition at line 447 of file calendar.c.

{
       long year, month, day;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) {
              RETURN_FALSE;
       }

       RETURN_LONG(GregorianToSdn(year, month, day));
}

Here is the call graph for this function:

PHP_FUNCTION ( jdtojulian  )

Definition at line 461 of file calendar.c.

{
       long julday;
       int year, month, day;
       char date[16];

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &julday) == FAILURE) {
              RETURN_FALSE;
       }

       SdnToJulian(julday, &year, &month, &day);
       snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);

       RETURN_STRING(date, 1);
}

Here is the call graph for this function:

PHP_FUNCTION ( juliantojd  )

Definition at line 480 of file calendar.c.

{
       long year, month, day;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) {
              RETURN_FALSE;
       }

       RETURN_LONG(JulianToSdn(year, month, day));
}

Here is the call graph for this function:

PHP_FUNCTION ( jdtojewish  )

Definition at line 589 of file calendar.c.

{
       long julday, fl = 0;
       zend_bool heb   = 0;
       int year, month, day;
       char date[16], hebdate[32];
       char *dayp, *yearp;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|bl", &julday, &heb, &fl) == FAILURE) {
              RETURN_FALSE;
       }

       SdnToJewish(julday, &year, &month, &day);
       if (!heb) {
              snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
              RETURN_STRING(date, 1);
       } else {
              if (year <= 0 || year > 9999) {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "Year out of range (0-9999).");
                     RETURN_FALSE;
              }

              snprintf(hebdate, sizeof(hebdate), "%s %s %s", heb_number_to_chars(day, fl, &dayp), JewishMonthHebName[month], heb_number_to_chars(year, fl, &yearp));

              if (dayp) {
                     efree(dayp);
              }
              if (yearp) {
                     efree(yearp);
              }

              RETURN_STRING(hebdate, 1);

       }
}

Here is the call graph for this function:

PHP_FUNCTION ( jewishtojd  )

Definition at line 628 of file calendar.c.

{
       long year, month, day;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) {
              RETURN_FALSE;
       }

       RETURN_LONG(JewishToSdn(year, month, day));
}

Here is the call graph for this function:

PHP_FUNCTION ( jdtofrench  )

Definition at line 642 of file calendar.c.

{
       long julday;
       int year, month, day;
       char date[16];

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &julday) == FAILURE) {
              RETURN_FALSE;
       }

       SdnToFrench(julday, &year, &month, &day);
       snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);

       RETURN_STRING(date, 1);
}

Here is the call graph for this function:

PHP_FUNCTION ( frenchtojd  )

Definition at line 661 of file calendar.c.

{
       long year, month, day;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &month, &day, &year) == FAILURE) {
              RETURN_FALSE;
       }

       RETURN_LONG(FrenchToSdn(year, month, day));
}

Here is the call graph for this function:

PHP_FUNCTION ( jddayofweek  )

Definition at line 675 of file calendar.c.

{
       long julday, mode = CAL_DOW_DAYNO;
       int day;
       char *daynamel, *daynames;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|l", &julday, &mode) == FAILURE) {
              RETURN_FALSE;
       }

       day = DayOfWeek(julday);
       daynamel = DayNameLong[day];
       daynames = DayNameShort[day];

       switch (mode) {
       case CAL_DOW_SHORT:
              RETURN_STRING(daynamel, 1);
              break;
       case CAL_DOW_LONG:
              RETURN_STRING(daynames, 1);
              break;
       case CAL_DOW_DAYNO:
       default:
              RETURN_LONG(day);
              break;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( jdmonthname  )

Definition at line 706 of file calendar.c.

{
       long julday, mode;
       char *monthname = NULL;
       int month, day, year;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &julday, &mode) == FAILURE) {
              RETURN_FALSE;
       }

       switch (mode) {
       case CAL_MONTH_GREGORIAN_LONG:     /* gregorian or julian month */
              SdnToGregorian(julday, &year, &month, &day);
              monthname = MonthNameLong[month];
              break;
       case CAL_MONTH_JULIAN_SHORT:       /* gregorian or julian month */
              SdnToJulian(julday, &year, &month, &day);
              monthname = MonthNameShort[month];
              break;
       case CAL_MONTH_JULIAN_LONG: /* gregorian or julian month */
              SdnToJulian(julday, &year, &month, &day);
              monthname = MonthNameLong[month];
              break;
       case CAL_MONTH_JEWISH:             /* jewish month */
              SdnToJewish(julday, &year, &month, &day);
              monthname = JewishMonthName[month];
              break;
       case CAL_MONTH_FRENCH:             /* french month */
              SdnToFrench(julday, &year, &month, &day);
              monthname = FrenchMonthName[month];
              break;
       default:                                  /* default gregorian */
       case CAL_MONTH_GREGORIAN_SHORT:    /* gregorian or julian month */
              SdnToGregorian(julday, &year, &month, &day);
              monthname = MonthNameShort[month];
              break;
       }

       RETURN_STRING(monthname, 1);
}

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:

PHP_FUNCTION ( easter_date  )

Definition at line 126 of file easter.c.

Here is the call graph for this function:

PHP_FUNCTION ( unixtojd  )

Definition at line 29 of file cal_unix.c.

{
       time_t ts = 0;
       struct tm *ta, tmbuf;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &ts) == FAILURE) {
              return;
       }      

       if (!ts) {
              ts = time(NULL);
       } else if (ts < 0) {
              RETURN_FALSE;
       }

       if (!(ta = php_localtime_r(&ts, &tmbuf))) {
              RETURN_FALSE;
       }

       RETURN_LONG(GregorianToSdn(ta->tm_year+1900, ta->tm_mon+1, ta->tm_mday));
}

Here is the call graph for this function:

PHP_FUNCTION ( jdtounix  )

Definition at line 54 of file cal_unix.c.

{
       long uday;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &uday) == FAILURE) {
              return;
       }      
       uday -= 2440588 /* J.D. of 1.1.1970 */;

       if (uday < 0 || uday > 24755) { /* before beginning of unix epoch or behind end of unix epoch */ 
              RETURN_FALSE;
       }

       RETURN_LONG(uday * 24 * 3600);
}

Here is the call graph for this function:

PHP_FUNCTION ( cal_from_jd  )

Definition at line 387 of file calendar.c.

{
       long jd, cal;
       int month, day, year, dow;
       char date[16];
       struct cal_entry_t *calendar;

       if (zend_parse_parameters(ZEND_NUM_ARGS()TSRMLS_CC, "ll", &jd, &cal) == FAILURE) {
              RETURN_FALSE;
       }

       if (cal < 0 || cal >= CAL_NUM_CALS) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %ld", cal);
              RETURN_FALSE;
       }
       calendar = &cal_conversion_table[cal];

       array_init(return_value);

       calendar->from_jd(jd, &year, &month, &day);

       snprintf(date, sizeof(date), "%i/%i/%i", month, day, year);
       add_assoc_string(return_value, "date", date, 1);

       add_assoc_long(return_value, "month", month);
       add_assoc_long(return_value, "day", day);
       add_assoc_long(return_value, "year", year);

/* day of week */
       dow = DayOfWeek(jd);
       add_assoc_long(return_value, "dow", dow);
       add_assoc_string(return_value, "abbrevdayname", DayNameShort[dow], 1);
       add_assoc_string(return_value, "dayname", DayNameLong[dow], 1);
/* month name */
       add_assoc_string(return_value, "abbrevmonth", calendar->month_name_short[month], 1);
       add_assoc_string(return_value, "monthname", calendar->month_name_long[month], 1);
}

Here is the call graph for this function:

PHP_FUNCTION ( cal_to_jd  )

Definition at line 368 of file calendar.c.

{
       long cal, month, day, year;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llll", &cal, &month, &day, &year) != SUCCESS) {
              RETURN_FALSE;
       }

       if (cal < 0 || cal >= CAL_NUM_CALS) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %ld.", cal);
              RETURN_FALSE;
       }

       RETURN_LONG(cal_conversion_table[cal].to_jd(year, month, day));
}

Here is the call graph for this function:

PHP_FUNCTION ( cal_days_in_month  )

Definition at line 324 of file calendar.c.

{
       long cal, month, year;
       struct cal_entry_t *calendar;
       long sdn_start, sdn_next;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "lll", &cal, &month, &year) == FAILURE) {
              RETURN_FALSE;
       }

       if (cal < 0 || cal >= CAL_NUM_CALS) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %ld.", cal);
              RETURN_FALSE;
       }

       calendar = &cal_conversion_table[cal];

       sdn_start = calendar->to_jd(year, month, 1);

       if (sdn_start == 0) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid date.");
              RETURN_FALSE;
       }

       sdn_next = calendar->to_jd(year, 1 + month, 1);

       if (sdn_next == 0) {
              /* If the next month is invalid, then we need to try the first month of
               * the next year, bearing in mind that the next year after 1 BCE is
               * actually 1 AD and not 0. */
              if (year == -1) {
                     sdn_next = calendar->to_jd(1, 1, 1);
              }
              else {
                     sdn_next = calendar->to_jd(year + 1, 1, 1);
              }
       }

       RETURN_LONG(sdn_next - sdn_start);
}

Here is the call graph for this function:

PHP_FUNCTION ( cal_info  )

Definition at line 288 of file calendar.c.

{
       long cal = -1;
       

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &cal) == FAILURE) {
              RETURN_FALSE;
       }

       if (cal == -1) {
              int i;
              zval *val;

              array_init(return_value);

              for (i = 0; i < CAL_NUM_CALS; i++) {
                     MAKE_STD_ZVAL(val);
                     _php_cal_info(i, &val);
                     add_index_zval(return_value, i, val);
              }
              return;
       }


       if (cal != -1 && (cal < 0 || cal >= CAL_NUM_CALS)) {
              php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid calendar ID %ld.", cal);
              RETURN_FALSE;
       }

       _php_cal_info(cal, &return_value);

}

Here is the call graph for this function:

PHP_MINFO_FUNCTION ( calendar  )

Definition at line 253 of file calendar.c.

Here is the call graph for this function:

PHP_MINIT_FUNCTION ( calendar  )

Definition at line 223 of file calendar.c.

{
       REGISTER_LONG_CONSTANT("CAL_GREGORIAN", CAL_GREGORIAN, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_JULIAN", CAL_JULIAN, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_JEWISH", CAL_JEWISH, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_FRENCH", CAL_FRENCH, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_NUM_CALS", CAL_NUM_CALS, CONST_CS | CONST_PERSISTENT);
/* constants for jddayofweek */
       REGISTER_LONG_CONSTANT("CAL_DOW_DAYNO", CAL_DOW_DAYNO, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_DOW_SHORT", CAL_DOW_SHORT, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_DOW_LONG", CAL_DOW_LONG, CONST_CS | CONST_PERSISTENT);
/* constants for jdmonthname */
       REGISTER_LONG_CONSTANT("CAL_MONTH_GREGORIAN_SHORT", CAL_MONTH_GREGORIAN_SHORT, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_MONTH_GREGORIAN_LONG", CAL_MONTH_GREGORIAN_LONG, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_MONTH_JULIAN_SHORT", CAL_MONTH_JULIAN_SHORT, CONST_CS | CONST_PERSISTENT);
       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);
/* constants for Jewish date formatting */
       REGISTER_LONG_CONSTANT("CAL_JEWISH_ADD_ALAFIM_GERESH", CAL_JEWISH_ADD_ALAFIM_GERESH, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_JEWISH_ADD_ALAFIM", CAL_JEWISH_ADD_ALAFIM, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("CAL_JEWISH_ADD_GERESHAYIM", CAL_JEWISH_ADD_GERESHAYIM, CONST_CS | CONST_PERSISTENT);
       return SUCCESS;
}

Variable Documentation

zend_module_entry calendar_module_entry

Definition at line 155 of file calendar.c.