DateUtil { public static DateRange getDateRangeForWeek(Calendar calendar) { DateRange weekRange = new DateRange(); Calendar calClone = (Calendar) calendar.clone(); DateUtil.dayOfWeekFix(calClone); calClone.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek()); weekRange.setDateStart(calClone.getTime()); calClone.add(Calendar.DAY_OF_MONTH, +6); weekRange.setDateEnd(calClone.getTime()); return weekRange; } private  DateUtil(); static int getWeekNumberForDate(Date date, int configuredFirstDayOfWeek); static void dayOfWeekFix(Calendar calendar); static boolean isWeekend(Calendar calendar); static int getDaysInMonth(Calendar calendar); static int getDaysInMonth(DateTime calendar); static DateRange calendarToMonthRange(Calendar calendar); static boolean isDateWithinRange(Date date, DateRange dateRange); static boolean isDateWithinRange(DateTime date, DateRange dateRange); static boolean isDateWithinRange(Calendar calendar, DateRange dateRange); static boolean isDateRangeOverlaps(DateRange rangeA, DateRange rangeB); static DateRange getDateRangeForWeek(Calendar calendar); static DateRange getDateRangeForMonth(Date date); static DateRange getDateRangeForMonth(Calendar calendar); static DateRange getDateRangeForQuarter(Calendar calendar); static Calendar addQuarter(Calendar calendar, int quarterDelta); static Date nullifyTime(Date date); static void nullifyTime(Calendar cal); static void maximizeTime(Calendar cal); static Date maximizeTime(Date date); static List<Date> createDateSequence(DateRange range, EhourConfig config); static Calendar getCalendar(EhourConfig config); static Calendar getCalendar(Date date); static String getPatternForDateLocale(Locale dateLocale); static String formatDate(Date date, Locale dateLocale); static String formatDate(DateTime date, Locale dateLocale); static String formatDate(LocalDate date, Locale dateLocale); static int fromCalendarToJodaTimeDayInWeek(int dayInWeek);  }
@Test public void testGetDateRangeForWeek() { Calendar cal = new GregorianCalendar(2007, 1 - 1, 1); cal.setFirstDayOfWeek(Calendar.SUNDAY); DateRange range = DateUtil.getDateRangeForWeek(cal); assertEquals(2006 - 1900, range.getDateStart().getYear()); assertEquals(12 - 1, range.getDateStart().getMonth()); assertEquals(31, range.getDateStart().getDate()); assertEquals(2007 - 1900, range.getDateEnd().getYear()); assertEquals(1 - 1, range.getDateEnd().getMonth()); assertEquals(6, range.getDateEnd().getDate()); }