Return-Path: Delivered-To: apmail-commons-dev-archive@www.apache.org Received: (qmail 39177 invoked from network); 17 Dec 2009 07:24:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 17 Dec 2009 07:24:02 -0000 Received: (qmail 20731 invoked by uid 500); 17 Dec 2009 07:24:01 -0000 Delivered-To: apmail-commons-dev-archive@commons.apache.org Received: (qmail 20591 invoked by uid 500); 17 Dec 2009 07:24:00 -0000 Mailing-List: contact dev-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Developers List" Delivered-To: mailing list dev@commons.apache.org Received: (qmail 20578 invoked by uid 99); 17 Dec 2009 07:24:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Dec 2009 07:24:00 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of flamefew@gmail.com designates 209.85.221.190 as permitted sender) Received: from [209.85.221.190] (HELO mail-qy0-f190.google.com) (209.85.221.190) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Dec 2009 07:23:51 +0000 Received: by qyk28 with SMTP id 28so858215qyk.28 for ; Wed, 16 Dec 2009 23:23:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=viRM+/JVuRa94gT7hS+TJbByoaKsPmX3au6mlIMTVys=; b=r3oZ3ys3KZiH6avz0Mtba32aVyDv7O9kcCWqAgHmjdPCmap3WVArkw1/PhaS4MjFQq yC6U8DyG7jU23elHQp0nMxaTYNVmkTVM2DLdw3pfvt1IYpcbeFFZxvezM7bF5TdMx28o fsIX/BjO1GDOU2B4Vo1Kdy9+uFFkprHYocy4c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=wMMRwhKohXZOnx88Pz+Lon+qOsLTmX9vFExNvktGW5K4Wj3pGgppJ0tUXEuG72ePBa +loVrzslodgaNaGgEplFhuf3zBUv/jW71tDy7jriDgabU3OT1T7x3V5yICjZFwnXkWmb OpuGuySwSq1xx0liZeKn8E5RrNImHpIfp4F3c= MIME-Version: 1.0 Received: by 10.229.90.68 with SMTP id h4mr1268620qcm.28.1261034610707; Wed, 16 Dec 2009 23:23:30 -0800 (PST) In-Reply-To: <20091217072125.E656F23889D1@eris.apache.org> References: <20091217072125.E656F23889D1@eris.apache.org> Date: Wed, 16 Dec 2009 23:23:30 -0800 Message-ID: <31cc37360912162323p2db2a97g49d4697bfe480f2e@mail.gmail.com> Subject: Re: svn commit: r891572 - in /commons/proper/lang/trunk/src: java/org/apache/commons/lang3/time/DateUtils.java test/org/apache/commons/lang3/time/DateUtilsTest.java From: Henri Yandell To: Commons Developers List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org Unless we implement FastDateFormat.parseObject fully, I couldn't see any good paths here and chose the least bad path. I think this change helps the common use case without incurring any pain on the abnormal use case (apart from the two endsWith checks). Opinions welcome as this didn't feel beautiful. On Wed, Dec 16, 2009 at 11:21 PM, wrote: > Author: bayard > Date: Thu Dec 17 07:21:25 2009 > New Revision: 891572 > > URL: http://svn.apache.org/viewvc?rev=3D891572&view=3Drev > Log: > Applying 'fix' for LANG-530. DateUtils.parseDate now protects the common = use case of FastDateFormat ZZ output, namely ZZ on the end of the pattern, = from being passed to SimpleDateFormat as is. Use of ZZ elsewhere in the pat= tern isn't protected and will want to consider emulating the String changes= made in this patch. > > Modified: > =A0 =A0commons/proper/lang/trunk/src/java/org/apache/commons/lang3/time/D= ateUtils.java > =A0 =A0commons/proper/lang/trunk/src/test/org/apache/commons/lang3/time/D= ateUtilsTest.java > > Modified: commons/proper/lang/trunk/src/java/org/apache/commons/lang3/tim= e/DateUtils.java > URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/java/org/= apache/commons/lang3/time/DateUtils.java?rev=3D891572&r1=3D891571&r2=3D8915= 72&view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- commons/proper/lang/trunk/src/java/org/apache/commons/lang3/time/Date= Utils.java (original) > +++ commons/proper/lang/trunk/src/java/org/apache/commons/lang3/time/Date= Utils.java Thu Dec 17 07:21:25 2009 > @@ -290,14 +290,29 @@ > =A0 =A0 =A0 =A0 SimpleDateFormat parser =3D null; > =A0 =A0 =A0 =A0 ParsePosition pos =3D new ParsePosition(0); > =A0 =A0 =A0 =A0 for (int i =3D 0; i < parsePatterns.length; i++) { > + > + =A0 =A0 =A0 =A0 =A0 =A0String pattern =3D parsePatterns[i]; > + > + =A0 =A0 =A0 =A0 =A0 =A0// LANG-530 - need to make sure 'ZZ' output does= n't get passed to SimpleDateFormat > + =A0 =A0 =A0 =A0 =A0 =A0if (parsePatterns[i].endsWith("ZZ")) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pattern =3D pattern.substring(0, pattern= .length() - 1); > + =A0 =A0 =A0 =A0 =A0 =A0} > + > =A0 =A0 =A0 =A0 =A0 =A0 if (i =3D=3D 0) { > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0parser =3D new SimpleDateFormat(parsePat= terns[0]); > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0parser =3D new SimpleDateFormat(pattern)= ; > =A0 =A0 =A0 =A0 =A0 =A0 } else { > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0parser.applyPattern(parsePatterns[i]); /= / cannot be null if i !=3D 0 > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0parser.applyPattern(pattern); // cannot = be null if i !=3D 0 > =A0 =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 =A0 =A0 pos.setIndex(0); > - =A0 =A0 =A0 =A0 =A0 =A0Date date =3D parser.parse(str, pos); > - =A0 =A0 =A0 =A0 =A0 =A0if (date !=3D null && pos.getIndex() =3D=3D str.= length()) { > + > + =A0 =A0 =A0 =A0 =A0 =A0String str2 =3D str; > + =A0 =A0 =A0 =A0 =A0 =A0// LANG-530 - need to make sure 'ZZ' output does= n't hit SimpleDateFormat as it will ParseException > + =A0 =A0 =A0 =A0 =A0 =A0if (parsePatterns[i].endsWith("ZZ")) { > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0str2 =3D str.replaceAll("([-+][0-9][0-9]= ):([0-9][0-9])$", "$1$2"); > + =A0 =A0 =A0 =A0 =A0 =A0} > + > + =A0 =A0 =A0 =A0 =A0 =A0Date date =3D parser.parse(str2, pos); > + =A0 =A0 =A0 =A0 =A0 =A0if (date !=3D null && pos.getIndex() =3D=3D str2= .length()) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 return date; > =A0 =A0 =A0 =A0 =A0 =A0 } > =A0 =A0 =A0 =A0 } > > Modified: commons/proper/lang/trunk/src/test/org/apache/commons/lang3/tim= e/DateUtilsTest.java > URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/org/= apache/commons/lang3/time/DateUtilsTest.java?rev=3D891572&r1=3D891571&r2=3D= 891572&view=3Ddiff > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D > --- commons/proper/lang/trunk/src/test/org/apache/commons/lang3/time/Date= UtilsTest.java (original) > +++ commons/proper/lang/trunk/src/test/org/apache/commons/lang3/time/Date= UtilsTest.java Thu Dec 17 07:21:25 2009 > @@ -1156,6 +1156,15 @@ > =A0 =A0 =A0 =A0 // restore default time zone > =A0 =A0 =A0 =A0 TimeZone.setDefault(defaultZone); > =A0 =A0 } > + > + =A0 =A0// http://issues.apache.org/jira/browse/LANG-520 > + =A0 =A0public void testLang520() throws ParseException { > + =A0 =A0 =A0 =A0Date d =3D new Date(); > + =A0 =A0 =A0 =A0String isoDateStr =3D DateFormatUtils.ISO_DATETIME_TIME_= ZONE_FORMAT.format(d); > + =A0 =A0 =A0 =A0Date d2 =3D DateUtils.parseDate(isoDateStr, new String[]= { DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern() }); > + =A0 =A0 =A0 =A0// the format loses milliseconds so have to reintroduce = them > + =A0 =A0 =A0 =A0assertEquals("Date not equal to itself ISO formatted and= parsed", d.getTime(), d2.getTime() + d.getTime() % 1000); > + =A0 =A0} > > =A0 =A0 /** > =A0 =A0 =A0* Tests various values with the ceiling method > > > --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org For additional commands, e-mail: dev-help@commons.apache.org