@Test public void testIsValidDateRange() { Calendar cal = Calendar.getInstance(); cal.set(2013, 8, 10); Date date1 = cal.getTime(); cal.set(2013, 9, 10); Date date2 = cal.getTime(); assertTrue(ValidatorUtil.isValidDateRange(date1, date2, "yyyy-MM-dd")); assertFalse(ValidatorUtil.isValidDateRange(date2, date1, "yyyy-MM-dd")); cal.set(2013, 9, 25); date1 = cal.getTime(); date2 = cal.getTime(); assertTrue(ValidatorUtil.isValidDateRange(date1, date2, "yyyy-MM-dd")); }
public static boolean isValidDateRange(Date dateField1, Date dateField2, String dateFormat) { if (dateField1 == null || dateField2 == null) return false; String strDate1 = DateUtil.dateToString(dateField1, dateFormat); String strDate2 = DateUtil.dateToString(dateField2, dateFormat); try { dateField1 = DateUtil.stringToDate(strDate1,dateFormat); dateField2 = DateUtil.stringToDate(strDate2, dateFormat); } catch (ParseException ee) { return false; } if (dateField1.getTime() <= dateField2.getTime()) return true; else return false; }
ValidatorUtil { public static boolean isValidDateRange(Date dateField1, Date dateField2, String dateFormat) { if (dateField1 == null || dateField2 == null) return false; String strDate1 = DateUtil.dateToString(dateField1, dateFormat); String strDate2 = DateUtil.dateToString(dateField2, dateFormat); try { dateField1 = DateUtil.stringToDate(strDate1,dateFormat); dateField2 = DateUtil.stringToDate(strDate2, dateFormat); } catch (ParseException ee) { return false; } if (dateField1.getTime() <= dateField2.getTime()) return true; else return false; } }
ValidatorUtil { public static boolean isValidDateRange(Date dateField1, Date dateField2, String dateFormat) { if (dateField1 == null || dateField2 == null) return false; String strDate1 = DateUtil.dateToString(dateField1, dateFormat); String strDate2 = DateUtil.dateToString(dateField2, dateFormat); try { dateField1 = DateUtil.stringToDate(strDate1,dateFormat); dateField2 = DateUtil.stringToDate(strDate2, dateFormat); } catch (ParseException ee) { return false; } if (dateField1.getTime() <= dateField2.getTime()) return true; else return false; } private  ValidatorUtil(); }
ValidatorUtil { public static boolean isValidDateRange(Date dateField1, Date dateField2, String dateFormat) { if (dateField1 == null || dateField2 == null) return false; String strDate1 = DateUtil.dateToString(dateField1, dateFormat); String strDate2 = DateUtil.dateToString(dateField2, dateFormat); try { dateField1 = DateUtil.stringToDate(strDate1,dateFormat); dateField2 = DateUtil.stringToDate(strDate2, dateFormat); } catch (ParseException ee) { return false; } if (dateField1.getTime() <= dateField2.getTime()) return true; else return false; } private  ValidatorUtil(); static boolean isEmail(String email); static boolean isPhoneNumber(String phoneNumber); static boolean isMatchRegex(String input, String regex); static boolean isNumeric(String number); static boolean isValidDateRange(Date dateField1, Date dateField2, String dateFormat); }
ValidatorUtil { public static boolean isValidDateRange(Date dateField1, Date dateField2, String dateFormat) { if (dateField1 == null || dateField2 == null) return false; String strDate1 = DateUtil.dateToString(dateField1, dateFormat); String strDate2 = DateUtil.dateToString(dateField2, dateFormat); try { dateField1 = DateUtil.stringToDate(strDate1,dateFormat); dateField2 = DateUtil.stringToDate(strDate2, dateFormat); } catch (ParseException ee) { return false; } if (dateField1.getTime() <= dateField2.getTime()) return true; else return false; } private  ValidatorUtil(); static boolean isEmail(String email); static boolean isPhoneNumber(String phoneNumber); static boolean isMatchRegex(String input, String regex); static boolean isNumeric(String number); static boolean isValidDateRange(Date dateField1, Date dateField2, String dateFormat);  }