This is two questions, one regarding identification, the other conversion.
Identification of possible date context is (relatively) easy, conversion is however deeply problematic for a number of reasons, notably the sheer variety of ways one can semantically express a date, and the concomitant ambiguities and misrepresentations which can emerge. Let's look at some obvious pitfalls here:
"The day after tomorrow 2pm." If we simply evaluate on "tomorrow 2pm" we are going to be a day adrift.
"Two days after 16.10.2010".. It gets worse...
"not much before 9pm Friday 13th March 2013" We can get the date back but the context renders it very ambiguous.
Assuming you only want to identify a potential date match in a String you could do something like this...
private final String[] datePatterns = {"Yesterday","Today","Tomorrow", //etc
"Sunday","Monday","Tuesday","Thursday","Friday", // etc
"Lundi","Mardi","Mercredi", //etc in French
"2001","2002", // all the years
"AM","PM",
"January","February","March","August"};
private List lx = new ArrayList();
public boolean mayContainDates(String toCheck)
{
toCheck = toCheck.toUpperCase();
// irl we'd build this list 1 time in the constructor
for(int i = 0; i < datePatterns.length; i++)
{
lx.add(datePatterns[i].toUpperCase());
}
Iterator lit = lx.iterator();
while(lit.hasNext())
{
if (toCheck.contains((String) lit.next())
{
return true;
}
}
return false;
}
It's really a question of how you set up your datePattern String array of comparators. Alternatively you could iterate an array of regexps in a somewhat similar fashion but it would be slow. You'll probably get a lot of false positives but you can obviously improve on this simple model.