/**
* First try parsing full date (month, day and year) using java.util.Date
* If that fails, try extracting at least part of the date
*/
public static Date parse(JCas jcas, String dateString) {
Date date = new Date(jcas);
try {
java.util.Date jud = df.parse(dateString);
// if no parse exception, create the CTS Date
date = new Date(jcas); // create new CTS Date
cal.setTime(jud);
date.setDay(Integer.toString(cal.get(Calendar.DAY_OF_MONTH)));// df.cal.get(Calendar.DAY_OF_MONTH, jud)));
date.setMonth(Integer.toString(cal.get(Calendar.MONTH)+1));
date.setYear(Integer.toString(cal.get(Calendar.YEAR)));
} catch (ParseException e) {
// An exception while parsing the date using java.util.Date
// Try to get just month and year or month and day etc
// possibilities to consider just for US dates
// m dd (ambiguous pattern with m yy, for at least some values)
// m yy (ambiguous pattern with m dd, for at least some values)
// m yyyy
// m dd yy
// m dd yyyy
dateString = dateString.trim().toLowerCase();
// look for month as string at beginning
for (int i=0; i<monthShortNames.size(); i++) {
if (dateString.startsWith(monthShortNames.get(i))) {
date.setMonth(dateString.substring(0, getIndexFirstNonLetter(dateString)));
}
}
// look for month as number
// look for day
// look for year as yy
// look for year as yyyy at end
int yearPosition = getIndexAfterLastNonDigit(dateString);
if (yearPosition+4==dateString.length()) {
date.setYear(dateString.substring(yearPosition));
}
}