TDI-32442: Data format of Dynamic is not surported for excel2003 and excel2007 with event mode.

Note: Modify ParserUtils.java to format non-dynamic date
https://jira.talendforge.org/browse/TDI-32442
This commit is contained in:
zzliu
2015-08-07 18:03:07 +08:00
parent 6e4c680d0a
commit bce770d005

View File

@@ -16,7 +16,9 @@ import java.io.IOException;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -274,6 +276,7 @@ public class ParserUtils {
public synchronized static java.util.Date parseTo_Date(String s, String pattern) {
// check the parameter for supporting " ","2007-09-13"," 2007-09-13 "
SimpleDateFormat baseDateFormat = new SimpleDateFormat("yyyy-MM-dd");
if (s != null) {
s = s.trim();
}
@@ -304,7 +307,24 @@ public class ParserUtils {
ParsePosition pp = new ParsePosition(0);
pp.setIndex(0);
date = format.parse(s, pp);
if (pattern.indexOf("dd-MM-yyyy") != -1) {
String[] dateArray = null;
if (pattern.indexOf("-") != -1) {
dateArray = s.split("-");
}
if (pattern.indexOf("/") != -1) {
dateArray = s.split("/");
}
if (dateArray != null && dateArray[0].length() == 4) {
try {
date = format.parse(format.format(baseDateFormat.parse(s)), pp);
} catch (ParseException e) {
e.printStackTrace();
}
}
}else{
date = format.parse(s, pp);
}
if (pp.getIndex() != s.length() || date == null) {
throw new RuntimeException("Unparseable date: \"" + s + "\""); //$NON-NLS-1$ //$NON-NLS-2$
}