cvs: php-src /ext/date php_date.c php_date.h /ext/standard basic_functions.c datetime.c

From: Date: Sun, 03 Jul 2005 20:45:08 +0000
Subject: cvs: php-src /ext/date php_date.c php_date.h /ext/standard basic_functions.c datetime.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-32663@lists.php.net to get a copy of this message
derick Sun Jul 3 16:45:08 2005 EDT Modified files: /php-src/ext/standard basic_functions.c datetime.c /php-src/ext/date php_date.c php_date.h Log: - Reimplemented time(), getdate() and localtime() functions with new datetime library.

http://cvs.php.net/diff.php/php-src/ext/standard/basic_functions.c?r1=1.723&r2=1.724&ty=u Index: php-src/ext/standard/basic_functions.c diff -u php-src/ext/standard/basic_functions.c:1.723 php-src/ext/standard/basic_functions.c:1.724 --- php-src/ext/standard/basic_functions.c:1.723 Sun Jul 3 15:14:54 2005 +++ php-src/ext/standard/basic_functions.c Sun Jul 3 16:45:07 2005 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.723 2005/07/03 19:14:54 derick Exp $ */ +/* $Id: basic_functions.c,v 1.724 2005/07/03 20:45:07 derick Exp $ */ #include "php.h" #include "php_streams.h" @@ -168,14 +168,12 @@ PHP_FE(time_nanosleep, NULL) PHP_FE(time_sleep_until, NULL) #endif - PHP_FE(time, NULL) + #if HAVE_STRPTIME PHP_FE(strptime, NULL) #endif PHP_FE(idate, NULL) - PHP_FE(getdate, NULL) - PHP_FE(localtime, NULL) PHP_FE(flush, NULL) PHP_FE(wordwrap, NULL) http://cvs.php.net/diff.php/php-src/ext/standard/datetime.c?r1=1.132&r2=1.133&ty=u Index: php-src/ext/standard/datetime.c diff -u php-src/ext/standard/datetime.c:1.132 php-src/ext/standard/datetime.c:1.133 --- php-src/ext/standard/datetime.c:1.132 Sun Jul 3 15:14:55 2005 +++ php-src/ext/standard/datetime.c Sun Jul 3 16:45:08 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: datetime.c,v 1.132 2005/07/03 19:14:55 derick Exp $ */ +/* $Id: datetime.c,v 1.133 2005/07/03 20:45:08 derick Exp $ */ #if HAVE_STRPTIME #define _XOPEN_SOURCE @@ -69,14 +69,6 @@ #define isleap(year) ((((year) % 4) == 0 && ((year) % 100) != 0) || ((year) % 400)==0) #define YEAR_BASE 1900 -/* {{{ proto int time(void) - Return current UNIX timestamp */ -PHP_FUNCTION(time) -{ - RETURN_LONG((long)time(NULL)); -} -/* }}} */ - /* {{{ php_idate */ PHPAPI int php_idate(char format, int timestamp, int gm) @@ -218,111 +210,6 @@ } /* }}} */ -/* {{{ proto array localtime([int timestamp [, bool associative_array]]) - Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */ -PHP_FUNCTION(localtime) -{ - zval **timestamp_arg, **assoc_array_arg; - struct tm *ta, tmbuf; - time_t timestamp; - int assoc_array = 0; - int arg_count = ZEND_NUM_ARGS(); - - if (arg_count < 0 || arg_count > 2 || - zend_get_parameters_ex(arg_count, &timestamp_arg, &assoc_array_arg) == FAILURE) { - WRONG_PARAM_COUNT; - } - - switch (arg_count) { - case 0: - timestamp = (long)time(NULL); - break; - case 1: - convert_to_long_ex(timestamp_arg); - timestamp = Z_LVAL_PP(timestamp_arg); - break; - case 2: - convert_to_long_ex(timestamp_arg); - convert_to_long_ex(assoc_array_arg); - timestamp = Z_LVAL_PP(timestamp_arg); - assoc_array = Z_LVAL_PP(assoc_array_arg); - break; - } - -#ifdef PHP_WIN32 - if (timestamp < 0) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Windows does not support negative values for this function"); - RETURN_FALSE - } -#endif - - if (NULL == (ta = php_localtime_r(&timestamp, &tmbuf))) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid local time"); - RETURN_FALSE; - } - array_init(return_value); - - if (assoc_array) { - add_assoc_long(return_value, "tm_sec", ta->tm_sec); - add_assoc_long(return_value, "tm_min", ta->tm_min); - add_assoc_long(return_value, "tm_hour", ta->tm_hour); - add_assoc_long(return_value, "tm_mday", ta->tm_mday); - add_assoc_long(return_value, "tm_mon", ta->tm_mon); - add_assoc_long(return_value, "tm_year", ta->tm_year); - add_assoc_long(return_value, "tm_wday", ta->tm_wday); - add_assoc_long(return_value, "tm_yday", ta->tm_yday); - add_assoc_long(return_value, "tm_isdst", ta->tm_isdst); - } else { - add_next_index_long(return_value, ta->tm_sec); - add_next_index_long(return_value, ta->tm_min); - add_next_index_long(return_value, ta->tm_hour); - add_next_index_long(return_value, ta->tm_mday); - add_next_index_long(return_value, ta->tm_mon); - add_next_index_long(return_value, ta->tm_year); - add_next_index_long(return_value, ta->tm_wday); - add_next_index_long(return_value, ta->tm_yday); - add_next_index_long(return_value, ta->tm_isdst); - } -} -/* }}} */ - -/* {{{ proto array getdate([int timestamp]) - Get date/time information */ -PHP_FUNCTION(getdate) -{ - pval **timestamp_arg; - struct tm *ta, tmbuf; - time_t timestamp; - - if (ZEND_NUM_ARGS() == 0) { - timestamp = time(NULL); - } else if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &timestamp_arg) == FAILURE) { - WRONG_PARAM_COUNT; - } else { - convert_to_long_ex(timestamp_arg); - timestamp = Z_LVAL_PP(timestamp_arg); - } - - ta = php_localtime_r(&timestamp, &tmbuf); - if (!ta) { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot perform date calculation"); - return; - } - array_init(return_value); - add_assoc_long(return_value, "seconds", ta->tm_sec); - add_assoc_long(return_value, "minutes", ta->tm_min); - add_assoc_long(return_value, "hours", ta->tm_hour); - add_assoc_long(return_value, "mday", ta->tm_mday); - add_assoc_long(return_value, "wday", ta->tm_wday); - add_assoc_long(return_value, "mon", ta->tm_mon + 1); - add_assoc_long(return_value, "year", ta->tm_year + 1900); - add_assoc_long(return_value, "yday", ta->tm_yday); - add_assoc_string(return_value, "weekday", day_full_names[ta->tm_wday], 1); - add_assoc_string(return_value, "month", mon_full_names[ta->tm_mon], 1); - add_index_long(return_value, 0, timestamp); -} -/* }}} */ - /* {{{ php_std_date Return date string in standard format for http headers */ PHPAPI char *php_std_date(time_t t TSRMLS_DC) http://cvs.php.net/diff.php/php-src/ext/date/php_date.c?r1=1.25&r2=1.26&ty=u Index: php-src/ext/date/php_date.c diff -u php-src/ext/date/php_date.c:1.25 php-src/ext/date/php_date.c:1.26 --- php-src/ext/date/php_date.c:1.25 Sun Jul 3 15:14:55 2005 +++ php-src/ext/date/php_date.c Sun Jul 3 16:45:08 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_date.c,v 1.25 2005/07/03 19:14:55 derick Exp $ */ +/* $Id: php_date.c,v 1.26 2005/07/03 20:45:08 derick Exp $ */ #include "php.h" #include "php_streams.h" @@ -29,14 +29,22 @@ #include <time.h> function_entry date_functions[] = { + PHP_FE(strtotime, NULL) PHP_FE(date, NULL) PHP_FE(gmdate, NULL) PHP_FE(mktime, NULL) PHP_FE(checkdate, NULL) PHP_FE(gmstrftime, NULL) + +#if HAVE_STRFTIME PHP_FE(strftime, NULL) PHP_FE(gmmktime, NULL) - PHP_FE(strtotime, NULL) +#endif + + PHP_FE(time, NULL) + PHP_FE(localtime, NULL) + PHP_FE(getdate, NULL) + PHP_FE(date_timezone_set, NULL) PHP_FE(date_timezone_get, NULL) {NULL, NULL, NULL} @@ -641,6 +649,93 @@ /* }}} */ #endif +/* {{{ proto int time(void) + Return current UNIX timestamp */ +PHP_FUNCTION(time) +{ + RETURN_LONG((long)time(NULL)); +} +/* }}} */ + +/* {{{ proto array localtime([int timestamp [, bool associative_array]]) + Returns the results of the C system call localtime as an associative array if the associative_array argument is set to 1 other wise it is a regular array */ +PHP_FUNCTION(localtime) +{ + long timestamp = (long)time(NULL); + int associative = 0; + timelib_tzinfo *tzi; + timelib_time *ts; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|lb", &timestamp, &associative) == FAILURE) { + RETURN_FALSE; + } + + tzi = get_timezone_info(TSRMLS_C); + ts = timelib_time_ctor(); + timelib_unixtime2local(ts, (timelib_sll) timestamp, tzi); + + array_init(return_value); + + if (associative) { + add_assoc_long(return_value, "tm_sec", ts->s); + add_assoc_long(return_value, "tm_min", ts->i); + add_assoc_long(return_value, "tm_hour", ts->h); + add_assoc_long(return_value, "tm_mday", ts->d); + add_assoc_long(return_value, "tm_mon", ts->m - 1); + add_assoc_long(return_value, "tm_year", ts->y - 1900); + add_assoc_long(return_value, "tm_wday", timelib_day_of_week(ts->y, ts->m, ts->d)); + add_assoc_long(return_value, "tm_yday", timelib_day_of_year(ts->y, ts->m, ts->d)); + add_assoc_long(return_value, "tm_isdst", ts->dst); + } else { + add_next_index_long(return_value, ts->s); + add_next_index_long(return_value, ts->i); + add_next_index_long(return_value, ts->h); + add_next_index_long(return_value, ts->d); + add_next_index_long(return_value, ts->m - 1); + add_next_index_long(return_value, ts->y- 1900); + add_next_index_long(return_value, timelib_day_of_week(ts->y, ts->m, ts->d)); + add_next_index_long(return_value, timelib_day_of_year(ts->y, ts->m, ts->d)); + add_next_index_long(return_value, ts->dst); + } + + timelib_time_dtor(ts); +} +/* }}} */ + +/* {{{ proto array getdate([int timestamp]) + Get date/time information */ +PHP_FUNCTION(getdate) +{ + long timestamp = (long)time(NULL); + timelib_tzinfo *tzi; + timelib_time *ts; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &timestamp) == FAILURE) { + RETURN_FALSE; + } + + tzi = get_timezone_info(TSRMLS_C); + ts = timelib_time_ctor(); + timelib_unixtime2local(ts, (timelib_sll) timestamp, tzi); + + array_init(return_value); + + add_assoc_long(return_value, "seconds", ts->s); + add_assoc_long(return_value, "minutes", ts->i); + add_assoc_long(return_value, "hours", ts->h); + add_assoc_long(return_value, "mday", ts->d); + add_assoc_long(return_value, "wday", timelib_day_of_week(ts->y, ts->m, ts->d)); + add_assoc_long(return_value, "mon", ts->m); + add_assoc_long(return_value, "year", ts->y); + add_assoc_long(return_value, "yday", timelib_day_of_year(ts->y, ts->m, ts->d)); + add_assoc_string(return_value, "weekday", day_full_names[timelib_day_of_week(ts->y, ts->m, ts->d)], 1); + add_assoc_string(return_value, "month", mon_full_names[ts->m - 1], 1); + add_index_long(return_value, 0, timestamp); + + timelib_time_dtor(ts); +} +/* }}} */ + PHP_FUNCTION(date_timezone_set) { char *zone; http://cvs.php.net/diff.php/php-src/ext/date/php_date.h?r1=1.9&r2=1.10&ty=u Index: php-src/ext/date/php_date.h diff -u php-src/ext/date/php_date.h:1.9 php-src/ext/date/php_date.h:1.10 --- php-src/ext/date/php_date.h:1.9 Sun Jul 3 15:14:55 2005 +++ php-src/ext/date/php_date.h Sun Jul 3 16:45:08 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_date.h,v 1.9 2005/07/03 19:14:55 derick Exp $ */ +/* $Id: php_date.h,v 1.10 2005/07/03 20:45:08 derick Exp $ */ #ifndef PHP_DATE_H #define PHP_DATE_H @@ -38,6 +38,10 @@ PHP_FUNCTION(gmstrftime); #endif +PHP_FUNCTION(time); +PHP_FUNCTION(localtime); +PHP_FUNCTION(getdate); + PHP_FUNCTION(date_timezone_set); PHP_FUNCTION(date_timezone_get);
« previous php.cvs (#32663) next »