commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang RELEASE-NOTES.txt
Date Sat, 16 Oct 2004 17:43:05 GMT
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 <code>SEMI_MONTH</code>
        * @return the rounded date
        * @throws IllegalArgumentException if the date is <code>null</code>
  +     * @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 <code>SEMI_MONTH</code>
        * @return the rounded date (a different object)
        * @throws IllegalArgumentException if the date is <code>null</code>
  +     * @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 <code>null</code>
        * @throws ClassCastException if the object type is not a <code>Date</code>
        *  or <code>Calendar</code>
  +     * @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 <code>SEMI_MONTH</code>
        * @return the rounded date
        * @throws IllegalArgumentException if the date is <code>null</code>
  +     * @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 <code>SEMI_MONTH</code>
        * @return the rounded date (a different object)
        * @throws IllegalArgumentException if the date is <code>null</code>
  +     * @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 <code>null</code>
        * @throws ClassCastException if the object type is not a
        *  <code>Date</code> or <code>Calendar</code>
  +     * @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


Mime
View raw message