DateUtil { public static int getWeekNumberForDate(Date date, int configuredFirstDayOfWeek) { DateTime dateTime = new DateTime(date); return configuredFirstDayOfWeek == Calendar.SUNDAY ? dateTime.plusDays(1).getWeekOfWeekyear() : dateTime.getWeekOfWeekyear(); } 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 should_return_week_35_for_august_28_with_Sunday_as_first_day_of_week() { assertEquals(35, DateUtil.getWeekNumberForDate(new GregorianCalendar(2011, 7, 28).getTime(), Calendar.SUNDAY)); }
@Test public void should_return_week_35_for_august_29_with_Monday_as_first_day_of_week() { assertEquals(35, DateUtil.getWeekNumberForDate(new GregorianCalendar(2011, 7, 29).getTime(), Calendar.MONDAY)); }
@Test public void should_return_week_1_for_january_1_2012_with_Sunday_as_first_day_of_week() { assertEquals(1, DateUtil.getWeekNumberForDate(new GregorianCalendar(2012, Calendar.JANUARY, 1).getTime(), Calendar.SUNDAY)); }