Author: bayard
Date: Sun Apr 30 22:32:43 2006
New Revision: 398530

URL: http://svn.apache.org/viewcvs?rev=398530&view=rev
Log:
Adding unit test for #39410. Implementing fix by switching from using Math.log 
to Integer.toString to figure out the number of digits. 

Modified:
    
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java
    
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java

Modified: 
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java?rev=398530&r1=398529&r2=398530&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/time/FastDateFormat.java
 Sun Apr 30 22:32:43 2006
@@ -31,6 +31,8 @@
 import java.util.Map;
 import java.util.TimeZone;
 
+import org.apache.commons.lang.Validate;
+
 /**
  * <p>FastDateFormat is a fast and thread-safe version of
  * [EMAIL PROTECTED] java.text.SimpleDateFormat}.</p>
@@ -93,9 +95,6 @@
      */
     public static final int SHORT = DateFormat.SHORT;
     
-    // package scoped as used by inner class
-    static final double LOG_10 = Math.log(10);
-
     private static String cDefaultPattern;
 
     private static Map cInstanceCache = new HashMap(7);
@@ -1283,7 +1282,8 @@
                 if (value < 1000) {
                     digits = 3;
                 } else {
-                    digits = (int)(Math.log(value) / LOG_10) + 1;
+                    Validate.isTrue(value > -1, "Negative values should not be 
possible", value);
+                    digits = Integer.toString(value).length();
                 }
                 for (int i = mSize; --i >= digits; ) {
                     buffer.append('0');

Modified: 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java?rev=398530&r1=398529&r2=398530&view=diff
==============================================================================
--- 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
 (original)
+++ 
jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
 Sun Apr 30 22:32:43 2006
@@ -251,6 +251,17 @@
         assertEquals("0999/01/01", format.format(cal));
     }
     /**
+     * Show Bug #39410 is solved
+     */
+    public void testMilleniumBug() {
+        Calendar cal = Calendar.getInstance();
+        FastDateFormat format = FastDateFormat.getInstance("dd.MM.yyyy");
+
+        cal.set(1000,0,1);
+        assertEquals("01.01.1000", format.format(cal));
+    }
+
+    /**
      * testLowYearPadding showed that the date was buggy
      * This test confirms it, getting 366 back as a date
      */



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

Reply via email to