Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C4762EF64 for ; Wed, 13 Feb 2013 16:45:26 +0000 (UTC) Received: (qmail 78839 invoked by uid 500); 13 Feb 2013 16:45:26 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 78776 invoked by uid 500); 13 Feb 2013 16:45:26 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 78766 invoked by uid 99); 13 Feb 2013 16:45:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Feb 2013 16:45:26 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 13 Feb 2013 16:45:23 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id D04D22388847; Wed, 13 Feb 2013 16:45:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1445725 - in /poi/trunk/src: java/org/apache/poi/ss/usermodel/DateUtil.java testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java Date: Wed, 13 Feb 2013 16:45:03 -0000 To: commits@poi.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130213164503.D04D22388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: nick Date: Wed Feb 13 16:45:03 2013 New Revision: 1445725 URL: http://svn.apache.org/r1445725 Log: Fix bug #54557 - Don't mis-detect format patterns like .000 as dates Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java?rev=1445725&r1=1445724&r2=1445725&view=diff ============================================================================== --- poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java (original) +++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DateUtil.java Wed Feb 13 16:45:03 2013 @@ -55,7 +55,8 @@ public class DateUtil { */ private static final Pattern date_ptrn1 = Pattern.compile("^\\[\\$\\-.*?\\]"); private static final Pattern date_ptrn2 = Pattern.compile("^\\[[a-zA-Z]+\\]"); - private static final Pattern date_ptrn3 = Pattern.compile("^[\\[\\]yYmMdDhHsS\\-/,. :\"\\\\]+0*[ampAMP/]*$"); + private static final Pattern date_ptrn3a = Pattern.compile("[yYmMdDhHsS]"); + private static final Pattern date_ptrn3b = Pattern.compile("^[\\[\\]yYmMdDhHsS\\-/,. :\"\\\\]+0*[ampAMP/]*$"); // elapsed time patterns: [h],[m] and [s] private static final Pattern date_ptrn4 = Pattern.compile("^\\[([hH]+|[mM]+|[sS]+)\\]"); @@ -364,10 +365,16 @@ public class DateUtil { fs = fs.substring(0, fs.indexOf(';')); } - // Otherwise, check it's only made up, in any case, of: - // y m d h s - \ / , . : + // Ensure it has some date letters in it + // (Avoids false positives on the rest of pattern 3) + if (! date_ptrn3a.matcher(fs).find()) { + return false; + } + + // If we get here, check it's only made up, in any case, of: + // y m d h s - \ / , . : [ ] // optionally followed by AM/PM - return date_ptrn3.matcher(fs).matches(); + return date_ptrn3b.matcher(fs).matches(); } /** Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java?rev=1445725&r1=1445724&r2=1445725&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java (original) +++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDateUtil.java Wed Feb 13 16:45:03 2013 @@ -499,5 +499,14 @@ public final class TestHSSFDateUtil exte assertEquals(valueToTest.getTime(), returnedValue.getTime()); } - + /** + * DateUtil.isCellFormatted(Cell) should not true for a numeric cell + * that's formatted as ".0000" + */ + public void testBug54557() throws Exception { + final String format = ".0000"; + boolean isDateFormat = HSSFDateUtil.isADateFormat(165, format); + + assertEquals(false, isDateFormat); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org