mirror of
https://github.com/php/php-src.git
synced 2024-11-23 09:54:15 +08:00
Add strptime function.
This commit is contained in:
parent
f890909ac4
commit
8f1a327edb
@ -548,6 +548,7 @@ strcoll \
|
||||
strdup \
|
||||
strerror \
|
||||
strftime \
|
||||
strptime \
|
||||
strstr \
|
||||
strtok_r \
|
||||
symlink \
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user