What is different in the Camel code is that we set setLenient(false) before
to parse the date -->
public Date parse(String string) throws Exception {
Date date;
DateFormat df = this.getDateFormat();
ObjectHelper.notNull(this.pattern, "pattern");
// Check length of the string with date pattern
// To avoid to parse a string date : 20090901-10:32:30 when
// the pattern is yyyyMMdd
if (string.length() <= this.pattern.length()) {
// Force the parser to be strict in the syntax of the date to be
// converted
df.setLenient(false);
date = df.parse(string);
return date;
} else {
throw new FormatException("Date provided does not fit the
pattern defined");
}
}
On Fri, Aug 29, 2014 at 4:30 PM, sandp <[email protected]> wrote:
> camel-bindy is throwing an *java.text.ParseException * on failing to parse
> date with format *"dd-MMM-yyyy hh"*
>
>
> *The date field in the CsvRecord is:*
> @DataField(pos = 1, required = true, pattern = "dd-MMM-yyyy hh")
>
>
> *Row from CSV file:*
> "10-Nov-2013 00","ARTHUR","2","CON ED NY CITY",332.8,90,90,,35,,70,,0,23512
>
>
> *Sample test below works fine:*
> private static void testDate(){
> String dateString="10-Nov-2013 00";
> SimpleDateFormat dateFormat = new
> SimpleDateFormat("dd-MMM-yyyy hh");
> Date date =null;
> try {
> date = dateFormat.parse(dateString);
> } catch (ParseException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
> System.out.println( " Formated date :" + date);
> }
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/camel-bindy-2-13-1-DateFormat-Unparseable-date-tp5755843.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
--
Charles Moulliard
Apache Committer / Architect @RedHat
Twitter : @cmoulliard | Blog : http://cmoulliard.github.io