CalendarService { public Date getNextLaboralDay(final Date date, final int days, final HolidayCalendar calendar) { DateTime tmp = new DateTime(date); int check = days < 0 ? Math.abs(days) - 1 : days; int count = 0; int increment = days < 0 ? -1 : 1; do { if (!isLaboralDay(tmp.toDate(), calendar)) { tmp = tmp.plusDays(increment); continue; } tmp = tmp.plusDays(increment); count++; } while (count < check); return tmp.toDate(); }  Date getNextLaboralDay(final Date date, final int days, final HolidayCalendar calendar); boolean isLaboralDay(Date date, HolidayCalendar calendar);  }
@Test public void test01() { CalendarService service = new CalendarService(); DateTime dt = new DateTime(2017, 10, 16, 0, 0, 0); Date result = service.getNextLaboralDay(dt.toDate(), 2, null); DateTime dtResult = new DateTime(result); Assert.assertEquals(2017, dtResult.getYear()); Assert.assertEquals(10, dtResult.getMonthOfYear()); Assert.assertEquals(18, dtResult.getDayOfMonth()); }
@Test public void test02() { CalendarService service = new CalendarService(); DateTime dt = new DateTime(2017, 10, 1, 0, 0, 0); Date result = service.getNextLaboralDay(dt.toDate(), 0, null); DateTime dtResult = new DateTime(result); Assert.assertEquals(2017, dtResult.getYear()); Assert.assertEquals(10, dtResult.getMonthOfYear()); Assert.assertEquals(2, dtResult.getDayOfMonth()); }
@Test public void test03() { CalendarService service = new CalendarService(); DateTime dt = new DateTime(2017, 10, 29, 0, 0, 0); Date result = service.getNextLaboralDay(dt.toDate(), -2, null); DateTime dtResult = new DateTime(result); Assert.assertEquals(2017, dtResult.getYear()); Assert.assertEquals(10, dtResult.getMonthOfYear()); Assert.assertEquals(26, dtResult.getDayOfMonth()); }