Here is the code I'm using. dtDateTimes can contain predefined vacation dates (for example, UK Bank Holidays) and dtConstants can contain duplicate things that you want to match, for example DateTimeConstants.SATURDAY .
public int numberOfOccurrencesInPeriod(final DateTime begin, final DateTime end, List<Integer> dtConstants, List<DateTime> dtDateTimes) { int counter = 0; for (DateTime current = begin; current.isBefore(end); current = current.plusDays(1)) { for (Integer constant : dtConstants) { if (current.dayOfWeek().get() == constant.intValue()) { counter++; } } for (DateTime dt : dtDateTimes) { if (current.getDayOfWeek() == (dt.getDayOfWeek())) { counter++; } } } return counter; } public boolean isInPeriod(final DateTime begin, final DateTime end, List<Integer> dtConstants, List<DateTime> dtDateTimes) { return numberOfOccurrencesInPeriod(begin, end, dtConstants, dtDateTimes) > 0; }
opyate
source share