/** * Tells you if the date part of a datetime is in a certain time range. */ @SuppressWarnings("deprecation") public static boolean isTimeInRange(java.sql.Time start, java.sql.Time end, java.util.Date d) { d = new java.sql.Time(d.getHours(), d.getMinutes(), d.getSeconds()); if (start == null || end == null) { return false; } if (start.before(end) && (!(d.after(start) && d.before(end)))) { return false; } if (end.before(start) && (!(d.after(end) || d.before(start)))) { return false; } return true; }
/** * Checks if the given range matches the actual time. If midnight is int the * given range like "22:00-4:00" it is splitted into two parts, * "22:00-24:00" and "0:00"-"4:00" and then checked. * * @param fromTo * the from to * @return true, if is time in rage */ private static boolean isTimeInRage(final String fromTo) { String[] range = fromTo.split("-"); Time t1 = Converter.toTime(range[0]); Time t2 = Converter.toTime(range[1]); String from = t1.toString(); String to = t2.toString(); if (t2.before(t1)) { String beforeMidnight = t1 + "-24:00"; String afterMidnight = "0:00-" + t2; return isTimeInRage(beforeMidnight) || isTimeInRage(afterMidnight); } if ("00:00:00".equals(to)) { to = "24:00:00"; } Time tnow = new Time(System.currentTimeMillis()); String now = tnow.toString(); return (now.compareTo(from) >= 0) && (now.compareTo(to) <= 0); }
if (!timeVal.equals(nowTime)) { if (isBeforeNow) { if (timeVal.before(nowTime)) { return true;