DateUtil { public static boolean inRange(DateTime reference, DateTime start, DateTime end) { return (isOnOrAfter(reference, start)) && (isOnOrBefore(reference, end)); } private  DateUtil(); static DateTime now(); static DateTime nowUTC(); static LocalDate today(); static LocalDate tomorrow(); static LocalDate newDate(int year, int month, int day); static DateTime newDateTime(LocalDate localDate, int hour, int minute, int second); static DateTime setTimeZone(DateTime dateTime); static DateTime setTimeZoneUTC(DateTime dateTime); static DateTime newDateTime(Date date); static DateTime newDateTime(LocalDate date); static Time time(DateTime dateTime); static LocalDate newDate(Date date); static LocalDate newDate(DateTime dateTime); static int daysPast(LocalDate localDate, DayOfWeek dayOfWeek); static boolean isOnOrBefore(DateTime firstDate, DateTime secondDate); static boolean isOnOrAfter(DateTime firstDate, DateTime secondDate); static boolean inRange(DateTime reference, DateTime start, DateTime end); static int daysToCalendarWeekEnd(LocalDate date, int calendarWeekStartDay); static DateTime newDateTime(LocalDate localDate, Time time); static DateTime newDateTime(int year, int month, int day, Time time); static DateTime newDateTime(int year, int month, int day); static DateTime newDateTime(int year, int month, int day, int hour, int minute, int second); static int getDifferenceOfDatesInYears(Date startDate); static DateTime endOfDay(Date dateTime); static DateTime nextApplicableWeekDay(DateTime fromDate, List<DayOfWeek> applicableDays); static DateTime nextApplicableWeekDayIncludingFromDate(DateTime fromDate, List<DayOfWeek> applicableDays); static List<DateTime> greaterThanOrEqualTo(final DateTime date, final List<DateTime> dates); static List<DateTime> lessThan(final DateTime date, final List<DateTime> dates); static List<DayOfWeek> daysStarting(DayOfWeek day, int numberOfDays); static List<DateTime> datesToDateTimes(List<Date> dates); static Date toDate(DateTime dateTime); static DateTime toDateTimeAtStartOfDay(LocalDate localDate);  }
@Test public void shouldReturnWhetherGivenDateTimeFallsUnderSpecifiedInclusiveRange() { DateTime reference = new DateTime(2010, 10, 10, 12, 22, 22, 223); assertTrue(DateUtil.inRange(reference, new DateTime(2010, 10, 9, 12, 22, 22, 223), new DateTime(2010, 10, 11, 12, 22, 22, 223))); assertTrue(DateUtil.inRange(reference, new DateTime(2010, 10, 10, 12, 22, 22, 223), new DateTime(2010, 10, 11, 12, 22, 22, 223))); assertTrue(DateUtil.inRange(reference, new DateTime(2010, 10, 9, 12, 22, 22, 223), new DateTime(2010, 10, 10, 12, 22, 22, 223))); assertFalse(DateUtil.inRange(reference, new DateTime(2010, 10, 9, 12, 22, 22, 223), new DateTime(2010, 10, 10, 12, 22, 22, 222))); assertFalse(DateUtil.inRange(reference, new DateTime(2010, 10, 10, 12, 22, 22, 224), new DateTime(2010, 10, 10, 12, 22, 22, 223))); assertTrue(DateUtil.inRange(reference, new DateTime(2010, 10, 9, 12, 22, 22, 224), new DateTime(2010, 10, 10, 12, 22, 22, 223))); }