ScheduleExpression { public Calendar ceil(Calendar cal) { if (contains(cal)) return cal; Calendar cal2 = new GregorianCalendar(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE)); if (!containsDayOfWeek(cal2)) do cal2.add(Calendar.DAY_OF_WEEK, 1); while (!containsDayOfWeek(cal2)); else cal2.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY)); while (!containsHour(cal2)) cal2.add(Calendar.HOUR_OF_DAY, 1); return cal2; }  static ScheduleExpression valueOf(String s); static ScheduleExpression[] valuesOf(String... ss); ScheduleExpression dayOfWeek(String s); ScheduleExpression hour(String s); String getDayOfWeek(); String getHour(); boolean contains(Calendar cal); static boolean emptyOrAnyContains(Calendar cal, ScheduleExpression... expressions); Calendar ceil(Calendar cal); static Calendar ceil(Calendar cal, ScheduleExpression... schedules); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testCeil() throws Exception { ScheduleExpression[] schedules = { ScheduleExpression.valueOf("hour=18-6 dayOfWeek=*"), ScheduleExpression.valueOf("hour=* dayOfWeek=0,6") }; assertEquals(new GregorianCalendar(2015, 9, 8, 18, 0), ScheduleExpression.ceil( new GregorianCalendar(2015, 9, 8, 10, 0), schedules)); assertEquals(new GregorianCalendar(2015, 9, 10, 10, 0), ScheduleExpression.ceil( new GregorianCalendar(2015, 9, 10, 10, 0), schedules)); }