@Test public void testWeek() { long now = 1164045917522L; now = correctBasedOnTimeZone(now); long expected = 1164499200000L; expected = correctBasedOnTimeZone(expected); Calendar cal = Calendar.getInstance(); cal.setTime(new Date(now)); int dayOffset = cal.getFirstDayOfWeek() - Calendar.SUNDAY; if (dayOffset != 0) { expected += 24L * 3600 * 1000 * (cal.getFirstDayOfWeek() - Calendar.SUNDAY); } long computed = TimeUtil.computeStartOfNextWeek(now); assertEquals(expected - now, 1000 * (3600 * (5 + 24 * (5 + dayOffset)) + 60 * 54 + 42) + 478); assertEquals(expected, computed); }
public static long computeStartOfNextWeek(long now) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(now)); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.WEEK_OF_YEAR, 1); return cal.getTime().getTime(); }
TimeUtil { public static long computeStartOfNextWeek(long now) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(now)); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.WEEK_OF_YEAR, 1); return cal.getTime().getTime(); } }
TimeUtil { public static long computeStartOfNextWeek(long now) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(now)); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.WEEK_OF_YEAR, 1); return cal.getTime().getTime(); }  }
TimeUtil { public static long computeStartOfNextWeek(long now) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(now)); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.WEEK_OF_YEAR, 1); return cal.getTime().getTime(); }  static long computeStartOfNextSecond(long now); static long computeStartOfNextMinute(long now); static long computeStartOfNextHour(long now); static long computeStartOfNextDay(long now); static long computeStartOfNextWeek(long now); static long computeStartOfNextMonth(long now); }
TimeUtil { public static long computeStartOfNextWeek(long now) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date(now)); cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); cal.add(Calendar.WEEK_OF_YEAR, 1); return cal.getTime().getTime(); }  static long computeStartOfNextSecond(long now); static long computeStartOfNextMinute(long now); static long computeStartOfNextHour(long now); static long computeStartOfNextDay(long now); static long computeStartOfNextWeek(long now); static long computeStartOfNextMonth(long now);  }