Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:13036 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 59357 invoked by uid 1010); 28 Sep 2004 04:15:24 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 59333 invoked from network); 28 Sep 2004 04:15:24 -0000 Received: from unknown (HELO mail.mbobo.org) (213.133.123.182) by pb1.pair.com with SMTP; 28 Sep 2004 04:15:24 -0000 Received: from localhost (localhost [127.0.0.1]) by mail.mbobo.org (Postfix) with ESMTP id 869BB5768E0; Tue, 28 Sep 2004 06:15:23 +0200 (CEST) Received: from mail.mbobo.org ([127.0.0.1]) by localhost (debian [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 10232-04; Tue, 28 Sep 2004 06:15:22 +0200 (CEST) Received: from [10.200.1.55] (adsl-68-120-96-254.dsl.sntc01.pacbell.net [68.120.96.254]) by mail.mbobo.org (Postfix) with ESMTP id CB2EA5768DE; Tue, 28 Sep 2004 06:15:21 +0200 (CEST) Message-ID: <4158E567.1070101@apache.org> Date: Mon, 27 Sep 2004 21:15:35 -0700 User-Agent: Mozilla Thunderbird 0.7.3 (X11/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: sterling@apache.org Cc: internals@lists.php.net References: <24e5f3b704092721131f22c678@mail.gmail.com> In-Reply-To: <24e5f3b704092721131f22c678@mail.gmail.com> Content-Type: multipart/mixed; boundary="------------070209020502090503050206" X-Virus-Scanned: by amavisd-new-20030616-p7 (Debian) at mbobo.org Subject: Re: [PHP-DEV] strptime patch From: sterling@apache.org (Sterling Hughes) --------------070209020502090503050206 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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 --------------070209020502090503050206 Content-Type: text/plain; name="strptime.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="strptime.diff" ? 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 --------------070209020502090503050206--