Add strptime function.

This commit is contained in:
Sterling Hughes 2004-09-29 04:57:19 +00:00
parent f890909ac4
commit 8f1a327edb
4 changed files with 46 additions and 1 deletions

View File

@ -548,6 +548,7 @@ strcoll \
strdup \
strerror \
strftime \
strptime \
strstr \
strtok_r \
symlink \

View File

@ -170,7 +170,9 @@ function_entry basic_functions[] = {
PHP_FE(time, NULL)
PHP_FE(mktime, NULL)
PHP_FE(gmmktime, NULL)
#if HAVE_STRPTIME
PHP_FE(strptime, NULL)
#endif
#if HAVE_STRFTIME
PHP_FE(strftime, NULL)
PHP_FE(gmstrftime, NULL)

View File

@ -20,6 +20,10 @@
/* $Id$ */
#if HAVE_STRPTIME
#define _XOPEN_SOURCE
#endif
#include "php.h"
#include "zend_operators.h"
#include "datetime.h"
@ -1094,6 +1098,41 @@ PHP_FUNCTION(strtotime)
}
/* }}} */
#if HAVE_STRPTIME
/* {{{ proto string strptime(string timestamp, string format)
Parse a time/date generated with strftime() */
PHP_FUNCTION(strptime)
{
char *ts;
int ts_length;
char *format;
int format_length;
struct tm parsed_time;
char *unparsed_part;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss",
&ts, &ts_length, &format, &format_length) == FAILURE) {
return;
}
unparsed_part = strptime(ts, format, &parsed_time);
if (unparsed_part == NULL) {
RETURN_FALSE;
}
array_init(return_value);
add_assoc_long(return_value, "tm_sec", parsed_time.tm_sec);
add_assoc_long(return_value, "tm_min", parsed_time.tm_min);
add_assoc_long(return_value, "tm_hour", parsed_time.tm_hour);
add_assoc_long(return_value, "tm_mday", parsed_time.tm_mday);
add_assoc_long(return_value, "tm_mon", parsed_time.tm_mon);
add_assoc_long(return_value, "tm_year", parsed_time.tm_year);
add_assoc_long(return_value, "tm_wday", parsed_time.tm_wday);
add_assoc_long(return_value, "tm_yday", parsed_time.tm_yday);
add_assoc_string(return_value, "unparsed", unparsed_part, 1);
}
/* }}} */
#endif
/*
* Local variables:

View File

@ -31,6 +31,9 @@ PHP_FUNCTION(gmdate);
PHP_FUNCTION(localtime);
PHP_FUNCTION(getdate);
PHP_FUNCTION(checkdate);
#if HAVE_STRPTIME
PHP_FUNCTION(strptime);
#endif
#if HAVE_STRFTIME
PHP_FUNCTION(strftime);
PHP_FUNCTION(gmstrftime);