DateUtil { public static DateRange getDateRangeForQuarter(Calendar calendar) { DateRange quarterRange; Calendar startMonth, endMonth; int month = calendar.get(Calendar.MONTH); int quarter = month / 3; startMonth = new GregorianCalendar(calendar.get(Calendar.YEAR), quarter * 3, 1); endMonth = new GregorianCalendar(calendar.get(Calendar.YEAR), quarter * 3, 1); endMonth.add(Calendar.MONTH, 3); endMonth.add(Calendar.DATE, -1); quarterRange = new DateRange(startMonth.getTime(), endMonth.getTime()); return quarterRange; } 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 testGetDateRangeForQuarter() { Calendar cal = new GregorianCalendar(2007, 12 - 1, 5); DateRange range = DateUtil.getDateRangeForQuarter(cal); assertEquals(2007 - 1900, range.getDateStart().getYear()); assertEquals(10 - 1, range.getDateStart().getMonth()); assertEquals(1, range.getDateStart().getDate()); assertEquals(2007 - 1900, range.getDateEnd().getYear()); assertEquals(12 - 1, range.getDateEnd().getMonth()); assertEquals(31, range.getDateEnd().getDate()); cal = new GregorianCalendar(2007, 5 - 1, 5); range = DateUtil.getDateRangeForQuarter(cal); assertEquals(2007 - 1900, range.getDateStart().getYear()); assertEquals(4 - 1, range.getDateStart().getMonth()); assertEquals(1, range.getDateStart().getDate()); assertEquals(2007 - 1900, range.getDateEnd().getYear()); assertEquals(6 - 1, range.getDateEnd().getMonth()); assertEquals(30, range.getDateEnd().getDate()); }