cvs: /php4/ext/standard datetime.c datetime.h basic_functions.c

From: Date: Tue, 28 Mar 2000 20:26:32 +0000
Subject: cvs: /php4/ext/standard datetime.c datetime.h basic_functions.c
Groups: php.version4 
Request: Send a blank email to php-version4+get-12765@lists.php.net to get a copy of this message
sterling Tue Mar 28 12:26:32 2000 EDT Modified files: /php4/ext/standard datetime.c datetime.h basic_functions.c Log: Index: php4/ext/standard/datetime.c diff -u php4/ext/standard/datetime.c:1.34 php4/ext/standard/datetime.c:1.35 --- php4/ext/standard/datetime.c:1.34 Tue Mar 28 10:16:41 2000 +++ php4/ext/standard/datetime.c Tue Mar 28 12:26:02 2000 @@ -19,7 +19,7 @@ */ -/* $Id: datetime.c,v 1.34 2000/03/28 18:16:41 sterling Exp $ */ +/* $Id: datetime.c,v 1.35 2000/03/28 20:26:02 sterling Exp $ */ #include "php.h" @@ -66,11 +66,13 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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) @@ -567,12 +589,10 @@ str[79]=0; 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 @@ } 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 @@ RETURN_FALSE; } format = (*format_arg)->value.str.val; - ta = localtime_r(&timestamp, &tmbuf); + if (gm) { + ta = gmtime_r(&timestamp, &tmbuf); + } else { + ta = localtime_r(&timestamp, &tmbuf); + } buf = (char *) emalloc(buf_len); while ((real_len=strftime(buf,buf_len,format,ta))==buf_len || real_len==0) { @@ -656,6 +679,22 @@ 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) Index: php4/ext/standard/datetime.h diff -u php4/ext/standard/datetime.h:1.5 php4/ext/standard/datetime.h:1.6 --- php4/ext/standard/datetime.h:1.5 Tue Mar 28 10:16:41 2000 +++ php4/ext/standard/datetime.h Tue Mar 28 12:26:02 2000 @@ -29,7 +29,7 @@ */ -/* $Id: datetime.h,v 1.5 2000/03/28 18:16:41 sterling Exp $ */ +/* $Id: datetime.h,v 1.6 2000/03/28 20:26:02 sterling Exp $ */ #ifndef _DATETIME_H #define _DATETIME_H @@ -44,10 +44,14 @@ 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 */ Index: php4/ext/standard/basic_functions.c diff -u php4/ext/standard/basic_functions.c:1.176 php4/ext/standard/basic_functions.c:1.177 --- php4/ext/standard/basic_functions.c:1.176 Tue Mar 28 10:16:41 2000 +++ php4/ext/standard/basic_functions.c Tue Mar 28 12:26:02 2000 @@ -87,6 +87,7 @@ PHP_FE(gmmktime, NULL) #if HAVE_STRFTIME PHP_FE(strftime, NULL) + PHP_FE(gmstrftime, NULL) #endif PHP_FE(strtotime, NULL) PHP_FE(date, NULL)

« previous php.version4 (#12765) next »