From: Sterling Hughes Date: Tue, 28 Mar 2000 20:26:02 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: php-4.0RC2~598 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=74d30dff7bb798a85327c5e2551b5b8ced2c3c96;p=php *** empty log message *** --- diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 96eaced044..30fed200be 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -87,6 +87,7 @@ function_entry basic_functions[] = { PHP_FE(gmmktime, NULL) #if HAVE_STRFTIME PHP_FE(strftime, NULL) + PHP_FE(gmstrftime, NULL) #endif PHP_FE(strtotime, NULL) PHP_FE(date, NULL) diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index 44c05e6979..35bd27e85d 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -66,11 +66,13 @@ static int phpday_tab[2][12] = extern PHPAPI time_t parsedate(char *p, struct timeval *now); - +/* {{{ proto int time(void) + Return current UNIX timestamp */ PHP_FUNCTION(time) { RETURN_LONG((long)time(NULL)); } +/* }}} */ void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm) { @@ -174,15 +176,21 @@ void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm) RETURN_LONG(seconds); } +/* {{{ proto int mktime(int hour, int min, int sec, int mon, int mday, int year) + Get UNIX timestamp for a date */ PHP_FUNCTION(mktime) { php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } +/* }}} */ +/* {{{ proto int gmmktime(int hour, int min, int sec, int mon, int mday, int year) + Get UNIX timestamp for a GMT date */ PHP_FUNCTION(gmmktime) { php_mktime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } +/* }}} */ static void php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) @@ -435,16 +443,26 @@ php_date(INTERNAL_FUNCTION_PARAMETERS, int gm) return_value->type = IS_STRING; } +/* {{{ proto string date(string format [, int timestamp]) + Format a local time/date */ PHP_FUNCTION(date) { php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); } +/* }}} */ +/* {{{ proto string gmdate(string format [, int timestamp]) + Format a GMT/CUT date/time */ PHP_FUNCTION(gmdate) { php_date(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); } +/* }}} */ +/* {{{ 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; @@ -501,7 +519,10 @@ PHP_FUNCTION(localtime) add_next_index_long(return_value, ta->tm_isdst); } } +/* }}} */ +/* {{{ proto array getdate([int timestamp]) + Get date/time information */ PHP_FUNCTION(getdate) { pval **timestamp_arg; @@ -538,6 +559,7 @@ PHP_FUNCTION(getdate) add_assoc_string(return_value, "month", mon_full_names[ta->tm_mon], 1); add_index_long(return_value, 0, timestamp); } +/* }}} */ /* Return date string in standard format for http headers */ char *php_std_date(time_t t) @@ -568,11 +590,9 @@ char *php_std_date(time_t t) return (str); } -/* - * CheckDate(month, day, year); - * returns True(1) if it is valid date - * - */ + +/* {{{ proto bool checkdate(int month, int day, int year) + Returns true(1) if it is a valid date */ PHP_FUNCTION(checkdate) { pval **month, **day, **year; @@ -603,11 +623,10 @@ PHP_FUNCTION(checkdate) } RETURN_TRUE; /* True : This month,day,year arguments are valid */ } - +/* }}} */ #if HAVE_STRFTIME - -PHP_FUNCTION(strftime) +void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm) { pval **format_arg, **timestamp_arg; char *format,*buf; @@ -640,7 +659,11 @@ PHP_FUNCTION(strftime) RETURN_FALSE; } format = (*format_arg)->value.str.val; - ta = localtime_r(×tamp, &tmbuf); + if (gm) { + ta = gmtime_r(×tamp, &tmbuf); + } else { + ta = localtime_r(×tamp, &tmbuf); + } buf = (char *) emalloc(buf_len); while ((real_len=strftime(buf,buf_len,format,ta))==buf_len || real_len==0) { @@ -656,6 +679,22 @@ PHP_FUNCTION(strftime) efree(buf); RETURN_FALSE; } +/* {{{ proto string strftime(string format [, int timestamp]) + Format a local time/date according to locale settings */ +PHP_FUNCTION(strftime) +{ + _php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0); +} +/* }}} */ + +/* {{{ proto string gmstrftime(string format [, int timestamp]) + Format a GMT/CUT time/date according to locale settings */ +PHP_FUNCTION(gmstrftime) +{ + _php_strftime(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1); +} +/* }}} */ + #endif /* {{{ proto int strtotime(string time, int now) diff --git a/ext/standard/datetime.h b/ext/standard/datetime.h index 2e8f61f53d..6171197c61 100644 --- a/ext/standard/datetime.h +++ b/ext/standard/datetime.h @@ -44,10 +44,14 @@ PHP_FUNCTION(getdate); PHP_FUNCTION(checkdate); #if HAVE_STRFTIME PHP_FUNCTION(strftime); +PHP_FUNCTION(gmstrftime); #endif PHP_FUNCTION(strtotime); extern char *php_std_date(time_t t); void php_mktime(INTERNAL_FUNCTION_PARAMETERS, int gm); +#if HAVE_STRFTIME +void _php_strftime(INTERNAL_FUNCTION_PARAMETERS, int gm); +#endif #endif /* _DATETIME_H */