classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

java.text.DecimalFormat && SimpleDateFormat


From: Guilhem Lavaux
Subject: java.text.DecimalFormat && SimpleDateFormat
Date: Sun, 16 May 2004 18:56:32 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030630

Hi,

Here are two related fixes concerning DecimalFormat and SimpleDateFormat. Without them, dates may be wrongly parsed, especially if they are encoded like that '04082004' for '04/08/2004'. DecimalFormat should stop at the right place based on the different parameters.

Cheers,

Guilhem.

ChangeLog entry:


        * java/text/DecimalFormat.java
        (parse): Fixed parsing of decimal strings. Number of maximum
        digits to be read should now work.


        * java/text/SimpleDateFormat.java:
        (SimpleDateFormat): Set maximumFractionDigit to 0 for the number
        formatter. This fixes DateFormatTest.


Index: java/text/DecimalFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/DecimalFormat.java,v
retrieving revision 1.15
diff -u -r1.15 DecimalFormat.java
--- java/text/DecimalFormat.java        1 May 2004 14:07:49 -0000       1.15
+++ java/text/DecimalFormat.java        16 May 2004 16:55:29 -0000
@@ -847,7 +847,7 @@
     // FIXME: handle Inf and NaN.
 
     // FIXME: do we have to respect minimum digits?
-    // What about leading zeros?  What about multiplier?
+    // What about multiplier?
 
     StringBuffer buf = int_buf;
     StringBuffer frac_buf = null;
@@ -855,7 +855,13 @@
     int start_index = index;
     int max = str.length();
     int exp_index = -1;
-    int last = index + MAXIMUM_INTEGER_DIGITS;
+    int last = index + maximumIntegerDigits; 
+
+    if (maximumFractionDigits > 0)
+      last += maximumFractionDigits + 1;
+    
+    if (useExponentialNotation)
+      last += minExponentDigits + 1;
 
     if (last > 0 && max > last)
       max = last;
Index: java/text/SimpleDateFormat.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/text/SimpleDateFormat.java,v
retrieving revision 1.27
diff -u -r1.27 SimpleDateFormat.java
--- java/text/SimpleDateFormat.java     28 Apr 2004 19:17:09 -0000      1.27
+++ java/text/SimpleDateFormat.java     16 May 2004 16:55:29 -0000
@@ -189,6 +189,7 @@
     numberFormat = NumberFormat.getInstance(locale);
     numberFormat.setGroupingUsed (false);
     numberFormat.setParseIntegerOnly (true);
+    numberFormat.setMaximumFractionDigits (0);
   }
   
   /**
@@ -216,6 +217,7 @@
     numberFormat = NumberFormat.getInstance(locale);
     numberFormat.setGroupingUsed (false);
     numberFormat.setParseIntegerOnly (true);
+    numberFormat.setMaximumFractionDigits (0);
   }
 
   /**
@@ -234,6 +236,7 @@
     numberFormat = NumberFormat.getInstance();
     numberFormat.setGroupingUsed (false);
     numberFormat.setParseIntegerOnly (true);
+    numberFormat.setMaximumFractionDigits (0);
   }
 
   // What is the difference between localized and unlocalized?  The

reply via email to

[Prev in Thread] Current Thread [Next in Thread]