From 8f1a327edb037b3af1c5e8f716acfd1f7858eac8 Mon Sep 17 00:00:00 2001 From: Sterling Hughes Date: Wed, 29 Sep 2004 04:57:19 +0000 Subject: Add strptime function. --- configure.in | 1 + ext/standard/basic_functions.c | 4 +++- ext/standard/datetime.c | 39 +++++++++++++++++++++++++++++++++++++++ ext/standard/datetime.h | 3 +++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 9ef5fdbae0..3c103e1115 100644 --- a/configure.in +++ b/configure.in @@ -548,6 +548,7 @@ strcoll \ strdup \ strerror \ strftime \ +strptime \ strstr \ strtok_r \ symlink \ diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index dd4299a9a3..ad5104ff5c 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -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) diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c index eb025e5302..21075cde1b 100644 --- a/ext/standard/datetime.c +++ b/ext/standard/datetime.c @@ -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: diff --git a/ext/standard/datetime.h b/ext/standard/datetime.h index a08c17f7e5..755d40611d 100644 --- a/ext/standard/datetime.h +++ b/ext/standard/datetime.h @@ -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); -- cgit v1.2.1