Sterling Hughes wrote:
hey,
i needed strptime() for a project i'm working on, its awful handy when you are making dates with strftime(). any objections to committing the attached patch?
-sterling
no love for gmail attachments apparently, attached is another effort.
-sterling
? foo.diff
Index: basic_functions.c
===================================================================
RCS file: /repository/php-src/ext/standard/basic_functions.c,v
retrieving revision 1.690
diff -u -r1.690 basic_functions.c
--- basic_functions.c 26 Sep 2004 21:55:21 -0000 1.690
+++ basic_functions.c 28 Sep 2004 04:11:53 -0000
@@ -172,6 +172,7 @@
PHP_FE(gmmktime,
NULL)
#if HAVE_STRFTIME
+ PHP_FE(strptime,
NULL)
PHP_FE(strftime,
NULL)
PHP_FE(gmstrftime,
NULL)
#endif
Index: datetime.c
===================================================================
RCS file: /repository/php-src/ext/standard/datetime.c,v
retrieving revision 1.123
diff -u -r1.123 datetime.c
--- datetime.c 25 Sep 2004 15:26:55 -0000 1.123
+++ datetime.c 28 Sep 2004 04:11:54 -0000
@@ -20,6 +20,10 @@
/* $Id: datetime.c,v 1.123 2004/09/25 15:26:55 hyanantha Exp $ */
+#if HAVE_STRFTIME
+#define _XOPEN_SOURCE
+#endif
+
#include "php.h"
#include "zend_operators.h"
#include "datetime.h"
@@ -1047,6 +1051,41 @@
}
/* }}} */
+/* {{{ 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);
+
+}
+/* }}} */
+
/* {{{ proto string strftime(string format [, int timestamp])
Format a local time/date according to locale settings */
PHP_FUNCTION(strftime)
Index: datetime.h
===================================================================
RCS file: /repository/php-src/ext/standard/datetime.h,v
retrieving revision 1.16
diff -u -r1.16 datetime.h
--- datetime.h 8 Jan 2004 17:32:51 -0000 1.16
+++ datetime.h 28 Sep 2004 04:11:54 -0000
@@ -32,6 +32,7 @@
PHP_FUNCTION(getdate);
PHP_FUNCTION(checkdate);
#if HAVE_STRFTIME
+PHP_FUNCTION(strptime);
PHP_FUNCTION(strftime);
PHP_FUNCTION(gmstrftime);
#endif-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
