java-tools / fixedformat4j

Automatically exported from code.google.com/p/fixedformat4j
0 stars 0 forks source link

DateFormatter removes paddingChars within the date pattern #33

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

If a field is mapped like this:

@Field(offset = 42, length = 20, paddingChar = '0')
@FixedFormatPattern("yyyyMMddHHmmss")
public Date getDatumErstellung() {
     return datumErstellung;
}

then input like 20120912111100000000 will become 201209121111 and therefore not 
parseable to the format yyyyMMddHHmmss. This is because the DateFormatter 
removes all paddingChars including the seconds field in this example because 
they are 00.

What do you see instead?

I think that the DateFormatter should only remove the paddingChars up until the 
length of the date pattern. It comes down the what happens in this method of 
AbstractFixedFormatter:

String getRemovePadding(String value, FormatInstructions instructions) {
    return instructions.getAlignment().remove(value, instructions.getPaddingChar());
  }

(a method which, by the way, should be protected)

I would override that in DateFormatter and change it to :

protected String getRemovePadding(String value, FormatInstructions 
instructions) {
        String newValue = instructions.getAlignment().remove(value, instructions.getPaddingChar());
        return instructions.getAlignment().apply(newValue, instructions.getFixedFormatPatternData().getPattern().length(), instructions.getPaddingChar());
    }

What version of the product are you using? On what Java version?

1.3.1, JDK 6

Please provide any additional information below.

Original issue reported on code.google.com by cmvag...@gmail.com on 12 Sep 2012 at 10:58