Beispiel #1
0
 /**
  * @param testY candidate year
  * @param testM candidate month in range 1 to 12
  * @param testD candidate day in range 1 to 31
  * @param leniant succeed even if the day and month might be ambiguous
  * @return Formatted date if certain date fields are OK and wouldn't be OK in a different order,
  *     else null
  */
 private String populateDateFieldsIfUnambiguous(int testY, int testM, int testD, boolean leniant) {
   if ((testY < 1600) || (testY > 4500)) {
     // Year does not fit within what Outlook allows, probably not what is intended
     return null;
   }
   int firstAllowableDay = leniant ? 1 : 13;
   if ((testD < firstAllowableDay) || (testD > 31)) {
     // Either an invalid date or could be a month number if guessed date string order wrong
     return null;
   }
   if ((testM < 1) || (testM > 12)) {
     // Not a valid month
     return null;
   }
   ICalTimeZone tzUTC = ICalTimeZone.getUTC();
   GregorianCalendar cal = new GregorianCalendar(tzUTC);
   cal.set(testY, testM - 1, 1, 0, 0);
   if (testD > cal.getActualMaximum(Calendar.DAY_OF_MONTH)) return null;
   cal.set(Calendar.DAY_OF_MONTH, testD);
   SimpleDateFormat ymd = new SimpleDateFormat("yyyy-MM-dd");
   ymd.setCalendar(cal);
   return ymd.format(cal.getTime());
 }