Skip to content

DateFormatter removes paddingChars within the date pattern  #33

@GoogleCodeExporter

Description

@GoogleCodeExporter
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 [email protected] on 12 Sep 2012 at 10:58

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions