DateUtil { public static boolean isDateRangeOverlaps(DateRange rangeA, DateRange rangeB) { boolean overlaps; boolean includeStart; boolean includeEnd; includeStart = rangeA.getDateStart() != null; includeEnd = rangeA.getDateEnd() != null; if (includeStart && includeEnd) { overlaps = rangeA.toInterval().overlaps(rangeB.toInterval()); } else if (!includeStart && includeEnd) { overlaps = rangeB.getDateStart().before(rangeA.getDateEnd()); } else if (includeStart && !includeEnd) { overlaps = rangeB.getDateEnd().after(rangeA.getDateStart()); } else { overlaps = true; } return overlaps; } 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 testIsDateRangeOverlapsNull() { DateRange rangeA = new DateRange(null, new GregorianCalendar(2006, 6, 5).getTime()); DateRange rangeB = new DateRange(new GregorianCalendar(2007, 5, 5).getTime(), new GregorianCalendar(2007, 6, 5).getTime()); assertFalse(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); rangeB = new DateRange(new GregorianCalendar(2006, 5, 20).getTime(), new GregorianCalendar(2007, 6, 5).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); rangeB = new DateRange(new GregorianCalendar(2006, 5, 20).getTime(), new GregorianCalendar(2006, 5, 25).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); rangeB = new DateRange(new GregorianCalendar(2006, 4, 20).getTime(), new GregorianCalendar(2006, 5, 25).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); rangeB = new DateRange(new GregorianCalendar(2006, 4, 20).getTime(), new GregorianCalendar(2006, 4, 30).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); rangeB = new DateRange(new GregorianCalendar(2006, 4, 20).getTime(), new GregorianCalendar(2006, 5, 5).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); }
@Test public void testIsDateRangeOverlaps() { DateRange rangeA = new DateRange(new GregorianCalendar(2006, 5, 5).getTime(), new GregorianCalendar(2006, 6, 5).getTime()); DateRange rangeB = new DateRange(new GregorianCalendar(2007, 5, 5).getTime(), new GregorianCalendar(2007, 6, 5).getTime()); assertFalse(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); rangeB = new DateRange(new GregorianCalendar(2006, 5, 20).getTime(), new GregorianCalendar(2007, 6, 5).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); assertTrue(DateUtil.isDateRangeOverlaps(rangeB, rangeA)); rangeB = new DateRange(new GregorianCalendar(2006, 5, 20).getTime(), new GregorianCalendar(2006, 5, 25).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); assertTrue(DateUtil.isDateRangeOverlaps(rangeB, rangeA)); rangeB = new DateRange(new GregorianCalendar(2006, 4, 20).getTime(), new GregorianCalendar(2006, 5, 25).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); assertTrue(DateUtil.isDateRangeOverlaps(rangeB, rangeA)); rangeB = new DateRange(new GregorianCalendar(2006, 4, 20).getTime(), new GregorianCalendar(2006, 4, 30).getTime()); assertFalse(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); assertFalse(DateUtil.isDateRangeOverlaps(rangeB, rangeA)); rangeB = new DateRange(new GregorianCalendar(2006, 4, 20).getTime(), new GregorianCalendar(2006, 5, 5).getTime()); assertTrue(DateUtil.isDateRangeOverlaps(rangeA, rangeB)); assertTrue(DateUtil.isDateRangeOverlaps(rangeB, rangeA)); }