Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:50092 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90478 invoked from network); 3 Nov 2010 17:16:41 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Nov 2010 17:16:41 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.153 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.153 smtp153.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.153] ([67.192.241.153:52586] helo=smtp153.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7C/00-24333-7F891DC4 for ; Wed, 03 Nov 2010 12:16:40 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp15.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id 6BA2B30003A for ; Wed, 3 Nov 2010 13:07:29 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp15.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 17B8C300162 for ; Wed, 3 Nov 2010 13:07:29 -0400 (EDT) Message-ID: <4CD196CF.2090800@sugarcrm.com> Date: Wed, 03 Nov 2010 10:07:27 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.9) Gecko/20100915 Thunderbird/3.1.4 MIME-Version: 1.0 To: PHP Internals Content-Type: multipart/mixed; boundary="------------000502020301020100000204" Subject: [PATCH] lenient datetime From: smalyshev@sugarcrm.com (Stas Malyshev) --------------000502020301020100000204 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi! As I previously noted, in DateTime module there's no way to make DateTime format parser to parse the string if the string contains more data that the format supplies - i.e. if you need 'Y-m-d' and you have string '2010-11-02 12:30' - you can't make DateTime accept it without pre-parsing. The attached patch adds format character '+' that implements that - i.e., if you use format 'Y-m-d+' then the string '2010-11-02 12:30' will be parsed successfully, as well as '2010-11-02' and string with anything following the date. The character would make the format 'lenient' when used in any position in the string, doesn't have to be at the end. Any objections? If not, I'll add some unit tests and commit it. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227 --------------000502020301020100000204 Content-Type: text/plain; x-mac-type="0"; x-mac-creator="0"; name="lenient_date.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="lenient_date.diff" Index: lib/parse_date.c =================================================================== --- lib/parse_date.c (revision 305040) +++ lib/parse_date.c (working copy) @@ -24824,6 +24824,7 @@ timelib_sll tmp; Scanner in; Scanner *s = ∈ + int allow_extra = 0; memset(&in, 0, sizeof(in)); in.errors = malloc(sizeof(struct timelib_error_container)); @@ -25046,7 +25047,9 @@ case '*': /* random chars until a separator or number ([ \t.,:;/-0123456789]) */ timelib_eat_until_separator((char **) &ptr); break; - + case '+': + allow_extra = 1; + break; default: if (*fptr != *ptr) { add_pbf_error(s, "The format separator does not match", string, begin); @@ -25055,9 +25058,10 @@ } fptr++; } - if (*ptr) { + if (*ptr && !allow_extra) { add_pbf_error(s, "Trailing data", string, ptr); } + while(*fptr == '+') fptr++; /* ignore trailing +'s */ if (*fptr) { add_pbf_error(s, "Data missing", string, ptr); } --------------000502020301020100000204--