Hello!

the next code throws NumberFormatException:

    Date d = new Date(77, 0, 1);
    System.out.println(d);
    System.out.println(DateField.stringToDate(DateField.dateToString(d)));


this caused by dateToString that adds some trailing space to the string:

+    if (s.length() < DATE_LEN) {
  +      StringBuffer sb = new StringBuffer(s);
  +      while (sb.length() < DATE_LEN)
  +        sb.insert(0, ' ');
  +      s = sb.toString();
  +    }
   
stringToDate calls Long.parseLong that throws the exception because of the spaces.

this code was checked in: 
http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg01512.html

I think the right code is:
// Pad with leading zeros
    if (s.length() < DATE_LEN) {
      StringBuffer sb = new StringBuffer(s);
      while (sb.length() < DATE_LEN)
        // sb.insert(0, ' ');
        sb.insert(0, '0');
      s = sb.toString();
    }


is it right?

peter

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

Reply via email to