@Test public void checkTimeTest() throws Exception{ String time1="1,1,1"; Assert.assertTrue(valuecheck.checkTime(time1)); String time2="12:12:12:12"; Assert.assertFalse(valuecheck.checkTime(time2)); String time3="66:12:12"; Assert.assertFalse(valuecheck.checkTime(time3)); String time4="22:66:12"; Assert.assertFalse(valuecheck.checkTime(time4)); String time5="21:12:66"; Assert.assertFalse(valuecheck.checkTime(time5)); String time6="12:12:12"; Assert.assertTrue(valuecheck.checkTime(time6)); String time7="2015-12-16-22,12:12:12"; Assert.assertFalse(valuecheck.checkTime(time7)); String time8="2015-66-16,12:12:12"; Assert.assertFalse(valuecheck.checkTime(time8)); String time9="2015-1-32,12:12:12"; Assert.assertFalse(valuecheck.checkTime(time9)); String time10="2015-4-31,12:12:12"; Assert.assertFalse(valuecheck.checkTime(time10)); String time11="2015-2-29,12:12:12"; Assert.assertFalse(valuecheck.checkTime(time11)); String time12="2015-2-28,12:12"; Assert.assertFalse(valuecheck.checkTime(time12)); String time13="2015-12-16,12:12:12"; Assert.assertTrue(valuecheck.checkTime(time13)); }
public Boolean checkTime(String time){ Boolean legalValue = true; String[] value = time.split(","); if (value.length == 1){ String[] hourMS = value[0].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } if (value.length == 2){ String[] yearMD = value[0].split("-"); if (yearMD.length!=3){ legalValue = false; } else { if (Integer.parseInt(yearMD[0])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])>12||Integer.parseInt(yearMD[1])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])==1||Integer.parseInt(yearMD[1])==3||Integer.parseInt(yearMD[1])==5||Integer.parseInt(yearMD[1])==7 ||Integer.parseInt(yearMD[1])==8||Integer.parseInt(yearMD[1])==10||Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>31||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==4||Integer.parseInt(yearMD[1])==6||Integer.parseInt(yearMD[1])==9 ||Integer.parseInt(yearMD[1])==11){ if (Integer.parseInt(yearMD[2])>30||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>28||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } } String[] hourMS = value[1].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } return legalValue; }
ValueCheck { public Boolean checkTime(String time){ Boolean legalValue = true; String[] value = time.split(","); if (value.length == 1){ String[] hourMS = value[0].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } if (value.length == 2){ String[] yearMD = value[0].split("-"); if (yearMD.length!=3){ legalValue = false; } else { if (Integer.parseInt(yearMD[0])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])>12||Integer.parseInt(yearMD[1])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])==1||Integer.parseInt(yearMD[1])==3||Integer.parseInt(yearMD[1])==5||Integer.parseInt(yearMD[1])==7 ||Integer.parseInt(yearMD[1])==8||Integer.parseInt(yearMD[1])==10||Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>31||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==4||Integer.parseInt(yearMD[1])==6||Integer.parseInt(yearMD[1])==9 ||Integer.parseInt(yearMD[1])==11){ if (Integer.parseInt(yearMD[2])>30||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>28||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } } String[] hourMS = value[1].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } return legalValue; } }
ValueCheck { public Boolean checkTime(String time){ Boolean legalValue = true; String[] value = time.split(","); if (value.length == 1){ String[] hourMS = value[0].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } if (value.length == 2){ String[] yearMD = value[0].split("-"); if (yearMD.length!=3){ legalValue = false; } else { if (Integer.parseInt(yearMD[0])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])>12||Integer.parseInt(yearMD[1])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])==1||Integer.parseInt(yearMD[1])==3||Integer.parseInt(yearMD[1])==5||Integer.parseInt(yearMD[1])==7 ||Integer.parseInt(yearMD[1])==8||Integer.parseInt(yearMD[1])==10||Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>31||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==4||Integer.parseInt(yearMD[1])==6||Integer.parseInt(yearMD[1])==9 ||Integer.parseInt(yearMD[1])==11){ if (Integer.parseInt(yearMD[2])>30||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>28||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } } String[] hourMS = value[1].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } return legalValue; }  }
ValueCheck { public Boolean checkTime(String time){ Boolean legalValue = true; String[] value = time.split(","); if (value.length == 1){ String[] hourMS = value[0].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } if (value.length == 2){ String[] yearMD = value[0].split("-"); if (yearMD.length!=3){ legalValue = false; } else { if (Integer.parseInt(yearMD[0])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])>12||Integer.parseInt(yearMD[1])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])==1||Integer.parseInt(yearMD[1])==3||Integer.parseInt(yearMD[1])==5||Integer.parseInt(yearMD[1])==7 ||Integer.parseInt(yearMD[1])==8||Integer.parseInt(yearMD[1])==10||Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>31||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==4||Integer.parseInt(yearMD[1])==6||Integer.parseInt(yearMD[1])==9 ||Integer.parseInt(yearMD[1])==11){ if (Integer.parseInt(yearMD[2])>30||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>28||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } } String[] hourMS = value[1].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } return legalValue; }  boolean checkMac(String macAddress); Boolean checkIpPrefix(String ipPrefix); Boolean checkIpAddress(String ipAddress); Boolean checkTime(String time); }
ValueCheck { public Boolean checkTime(String time){ Boolean legalValue = true; String[] value = time.split(","); if (value.length == 1){ String[] hourMS = value[0].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } if (value.length == 2){ String[] yearMD = value[0].split("-"); if (yearMD.length!=3){ legalValue = false; } else { if (Integer.parseInt(yearMD[0])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])>12||Integer.parseInt(yearMD[1])<1){ legalValue = false; } if (Integer.parseInt(yearMD[1])==1||Integer.parseInt(yearMD[1])==3||Integer.parseInt(yearMD[1])==5||Integer.parseInt(yearMD[1])==7 ||Integer.parseInt(yearMD[1])==8||Integer.parseInt(yearMD[1])==10||Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>31||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==4||Integer.parseInt(yearMD[1])==6||Integer.parseInt(yearMD[1])==9 ||Integer.parseInt(yearMD[1])==11){ if (Integer.parseInt(yearMD[2])>30||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } if (Integer.parseInt(yearMD[1])==2){ if (Integer.parseInt(yearMD[2])>28||Integer.parseInt(yearMD[2])<1){ legalValue = false; } } } String[] hourMS = value[1].split(":"); if (hourMS.length!=3){ legalValue = false; } else { if (Integer.parseInt(hourMS[0])>23||Integer.parseInt(hourMS[0])<0){ legalValue = false; } if (Integer.parseInt(hourMS[1])>59||Integer.parseInt(hourMS[1])<0){ legalValue = false; } if (Integer.parseInt(hourMS[2])>59||Integer.parseInt(hourMS[2])<0){ legalValue = false; } } } return legalValue; }  boolean checkMac(String macAddress); Boolean checkIpPrefix(String ipPrefix); Boolean checkIpAddress(String ipAddress); Boolean checkTime(String time);  }