Hi,
I've created a test to evaluate an informed date:
public void configureDateFormat(Binder binder) {
binder.bind(String.class).annotatedWith(Names.named("dateFormat"))
.toInstance("dd/MM/YYYY");
}
@Test
def void testParsingLibraryAttributes() {
val library = '''
libraryID library.templates.core.base
description "My description"
creationDate "10/01/2012a"
creator cvgaviao
}
'''.parse
assertEquals("library.templates.core.base", library.getName())
}
@Inject
@Named("dateFormat")
private String dateFormat;
@Override
protected Date internalToValue(String string, INode node)
throws ValueConverterException {
string = string.substring(1, string.length() - 1);
try {
SimpleDateFormat fmt = new SimpleDateFormat(dateFormat);
fmt.setTimeZone(TimeZone.getTimeZone(timeZoneFormat));
return fmt.parse(string);
} catch (Exception e) {
// ignore and try timestamp format
System.err.println(e.getMessage());
throw new ValueConverterException(
"Not in timestamp format", node,
new IllegalArgumentException());
}
With some debugging I could note that the converter is failing because a Illegal pattern character 'Y'. but the test are green...
could someone help to identify I'm missing ?
thanks.
Cristiano