bayard      2004/09/11 22:03:26

  Modified:    lang/src/java/org/apache/commons/lang/time
                        FastDateFormat.java
               lang/src/test/org/apache/commons/lang/time
                        FastDateFormatTest.java
  Log:
  Fix for zero-padding of years.
  
  A commented out set of failing tests are added to the Unit Test and need to be 
addressed.
  
  Submitted by: Jerson Chua
  
  Revision  Changes    Path
  1.21      +2 -2      
jakarta-commons/lang/src/java/org/apache/commons/lang/time/FastDateFormat.java
  
  Index: FastDateFormat.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/time/FastDateFormat.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- FastDateFormat.java       5 Jul 2004 22:37:40 -0000       1.20
  +++ FastDateFormat.java       12 Sep 2004 05:03:26 -0000      1.21
  @@ -591,7 +591,7 @@
                   break;
               case 'y': // year (number)
                   if (tokenLen >= 4) {
  -                    rule = UnpaddedNumberField.INSTANCE_YEAR;
  +                    rule = selectNumberRule(Calendar.YEAR, tokenLen);
                   } else {
                       rule = TwoDigitYearField.INSTANCE;
                   }
  
  
  
  1.10      +34 -1     
jakarta-commons/lang/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
  
  Index: FastDateFormatTest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/time/FastDateFormatTest.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FastDateFormatTest.java   5 Jul 2004 22:37:40 -0000       1.9
  +++ FastDateFormatTest.java   12 Sep 2004 05:03:26 -0000      1.10
  @@ -233,4 +233,37 @@
           assertEquals("2004-02-03", fdf.format(cal));
   
       }
  +
  +    /**
  +     * Tests that pre-1000AD years get padded with yyyy
  +     */
  +    public void testLowYearPadding() {
  +        Calendar cal = Calendar.getInstance();
  +        FastDateFormat format = FastDateFormat.getInstance("yyyy/MM/DD");
  +
  +        cal.set(1,0,1);
  +        assertEquals("0001/01/01", format.format(cal));
  +        cal.set(10,0,1);
  +        assertEquals("0010/01/01", format.format(cal));
  +        cal.set(100,0,1);
  +        assertEquals("0100/01/01", format.format(cal));
  +        cal.set(999,0,1);
  +        assertEquals("0999/01/01", format.format(cal));
  +    }
  +    /**
  +     * testLowYearPadding showed that the date was buggy
  +     * This test confirms it, getting 366 back as a date
  +     // TODO: Fix this problem
  +    public void testSimpleDate() {
  +        Calendar cal = Calendar.getInstance();
  +        FastDateFormat format = FastDateFormat.getInstance("yyyy/MM/DD");
  +
  +        cal.set(2004,11,31);
  +        assertEquals("2004/12/31", format.format(cal));
  +        cal.set(999,11,31);
  +        assertEquals("0999/12/31", format.format(cal));
  +        cal.set(1,2,2);
  +        assertEquals("0001/03/02", format.format(cal));
  +    }
  +    */
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to