lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Halácsy Péter <halacsy.pe...@axelero.com>
Subject NumberFormatException: DateField
Date Tue, 30 Jul 2002 15:05:05 GMT
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:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message