From: Sterling Hughes Date: Tue, 28 Mar 2000 18:16:41 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: php-4.0RC2~599 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f76e0a407768781919da031748b5afa93953ecad;p=php *** empty log message *** --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 6ae12fb939..96eaced044 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -92,6 +92,7 @@ function_entry basic_functions[] = { PHP_FE(date, NULL) PHP_FE(gmdate, NULL) PHP_FE(getdate, NULL) + PHP_FE(localtime, NULL) PHP_FE(checkdate, NULL) PHP_FE(flush, NULL) diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index 6604e21408..44c05e6979 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -445,6 +445,63 @@ PHP_FUNCTION(gmdate) php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } +PHP_FUNCTION(localtime) +{ + zval **timestamp_arg, **assoc_array_arg; + struct tm *ta, tmbuf; + time_t timestamp; + int assoc_array = 0; + int arg_count = ARG_COUNT(ht); + + if (arg_count < 0 || arg_count > 2 || + zend_get_parameters_ex(arg_count, ×tamp_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 = (*timestamp_arg)->value.lval; + break; + case 2: + convert_to_long_ex(timestamp_arg); + convert_to_long_ex(assoc_array_arg); + timestamp = (*timestamp_arg)->value.lval; + assoc_array = (*assoc_array_arg)->value.lval; + break; + } + ta = localtime_r(×tamp, &tmbuf); + if (array_init(return_value) == FAILURE) { + php_error(E_ERROR, "Cannot prepare return array from localtime"); + RETURN_FALSE; + } + + 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); + } +} + PHP_FUNCTION(getdate) { pval **timestamp_arg; diff --git a/ext/standard/datetime.h b/ext/standard/datetime.h index eaff52648b..2e8f61f53d 100644 --- a/ext/standard/datetime.h +++ b/ext/standard/datetime.h @@ -39,6 +39,7 @@ PHP_FUNCTION(mktime); PHP_FUNCTION(gmmktime); PHP_FUNCTION(date); PHP_FUNCTION(gmdate); +PHP_FUNCTION(localtime); PHP_FUNCTION(getdate); PHP_FUNCTION(checkdate); #if HAVE_STRFTIME