Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 56920 invoked from network); 16 Oct 2004 17:43:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 16 Oct 2004 17:43:10 -0000 Received: (qmail 36785 invoked by uid 500); 16 Oct 2004 17:43:09 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 36464 invoked by uid 500); 16 Oct 2004 17:43:06 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 36451 invoked by uid 500); 16 Oct 2004 17:43:06 -0000 Received: (qmail 36448 invoked by uid 99); 16 Oct 2004 17:43:06 -0000 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sat, 16 Oct 2004 10:43:06 -0700 Received: (qmail 56842 invoked by uid 1529); 16 Oct 2004 17:43:05 -0000 Date: 16 Oct 2004 17:43:05 -0000 Message-ID: <20041016174305.56841.qmail@minotaur.apache.org> From: scolebourne@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/lang RELEASE-NOTES.txt X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N scolebourne 2004/10/16 10:43:05 Modified: lang/src/test/org/apache/commons/lang/time DateUtilsTest.java lang/src/java/org/apache/commons/lang/time DateUtils.java lang RELEASE-NOTES.txt Log: Fix DateUtils.truncate oddity at the far end of the Date spectrum bug 31395, from Marc Portier Revision Changes Path 1.20 +17 -0 jakarta-commons/lang/src/test/org/apache/commons/lang/time/DateUtilsTest.java Index: DateUtilsTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/time/DateUtilsTest.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- DateUtilsTest.java 16 Oct 2004 17:08:42 -0000 1.19 +++ DateUtilsTest.java 16 Oct 2004 17:43:05 -0000 1.20 @@ -628,6 +628,23 @@ DateUtils.truncate((Object) cal8, Calendar.DATE)); TimeZone.setDefault(defaultZone); dateTimeParser.setTimeZone(defaultZone); + + // Bug 31395, large dates + Date endOfTime = new Date(Long.MAX_VALUE); // fyi: Sun Aug 17 07:12:55 CET 292278994 -- 807 millis + GregorianCalendar endCal = new GregorianCalendar(); + endCal.setTime(endOfTime); + try { + DateUtils.truncate(endCal, Calendar.DATE); + fail(); + } catch (ArithmeticException ex) {} + endCal.set(Calendar.YEAR, 280000001); + try { + DateUtils.truncate(endCal, Calendar.DATE); + fail(); + } catch (ArithmeticException ex) {} + endCal.set(Calendar.YEAR, 280000000); + Calendar cal = DateUtils.truncate(endCal, Calendar.DATE); + assertEquals(0, cal.get(Calendar.HOUR)); } /** 1.34 +12 -1 jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java Index: DateUtils.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/time/DateUtils.java,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- DateUtils.java 16 Oct 2004 17:08:42 -0000 1.33 +++ DateUtils.java 16 Oct 2004 17:43:05 -0000 1.34 @@ -255,6 +255,7 @@ * or SEMI_MONTH * @return the rounded date * @throws IllegalArgumentException if the date is null + * @throws ArithmeticException if the year is over 280 million */ public static Date round(Date date, int field) { if (date == null) { @@ -292,6 +293,7 @@ * or SEMI_MONTH * @return the rounded date (a different object) * @throws IllegalArgumentException if the date is null + * @throws ArithmeticException if the year is over 280 million */ public static Calendar round(Calendar date, int field) { if (date == null) { @@ -330,6 +332,7 @@ * @throws IllegalArgumentException if the date is null * @throws ClassCastException if the object type is not a Date * or Calendar + * @throws ArithmeticException if the year is over 280 million */ public static Date round(Object date, int field) { if (date == null) { @@ -359,6 +362,7 @@ * or SEMI_MONTH * @return the rounded date * @throws IllegalArgumentException if the date is null + * @throws ArithmeticException if the year is over 280 million */ public static Date truncate(Date date, int field) { if (date == null) { @@ -384,6 +388,7 @@ * or SEMI_MONTH * @return the rounded date (a different object) * @throws IllegalArgumentException if the date is null + * @throws ArithmeticException if the year is over 280 million */ public static Calendar truncate(Calendar date, int field) { if (date == null) { @@ -412,6 +417,7 @@ * is null * @throws ClassCastException if the object type is not a * Date or Calendar + * @throws ArithmeticException if the year is over 280 million */ public static Date truncate(Object date, int field) { if (date == null) { @@ -433,8 +439,13 @@ * @param val the calendar * @param field the field constant * @param round true to round, false to truncate + * @throws ArithmeticException if the year is over 280 million */ private static void modify(Calendar val, int field, boolean round) { + if (val.get(Calendar.YEAR) > 280000000) { + throw new ArithmeticException("Calendar value too large for accurate calculations"); + } + boolean roundUp = false; for (int i = 0; i < fields.length; i++) { for (int j = 0; j < fields[i].length; j++) { 1.30 +2 -1 jakarta-commons/lang/RELEASE-NOTES.txt Index: RELEASE-NOTES.txt =================================================================== RCS file: /home/cvs/jakarta-commons/lang/RELEASE-NOTES.txt,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- RELEASE-NOTES.txt 16 Oct 2004 17:08:42 -0000 1.29 +++ RELEASE-NOTES.txt 16 Oct 2004 17:43:05 -0000 1.30 @@ -115,3 +115,4 @@ 31478 Compile error with JDK 5 "enum" is a keyword 31572 o.a.c.lang.enum.ValuedEnum: 'enum'is a keyword in JDK1.5.0 26922 public static boolean DateUtils.equals(Date dt1, Date dt2) +31395 DateUtils.truncate oddity at the far end of the Date spectrum --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org