@Override public LocalDate next() { LocalDate result = current; current = plusDays(current, 1); return result; }
@Override public LocalDate shift(LocalDate date, int amount) { return plusDays(date, amount); }
@Override public LocalDate next(LocalDate date) { return plusDays(date, 1); }
@Override public LocalDate previous(LocalDate date) { return plusDays(date, -1); }
/** * Finds the next date in the sequence, always returning a date later than the input date. * <p> * Given an input date, this method returns the next date after it from the sequence. * * @param date the input date * @return the next sequence date after the input date * @throws IllegalArgumentException if there are no more sequence dates */ public default LocalDate next(LocalDate date) { LocalDate next = plusDays(date, 1); return nextOrSame(next); }
/** * Finds the next business day, always returning a later date. * <p> * Given a date, this method returns the next business day. * * @param date the date to adjust * @return the first business day after the input date * @throws IllegalArgumentException if the calculation is outside the supported range */ public default LocalDate next(LocalDate date) { LocalDate next = plusDays(date, 1); return isHoliday(next) ? next(next) : next; }
/** * Finds the previous business day, always returning an earlier date. * <p> * Given a date, this method returns the previous business day. * * @param date the date to adjust * @return the first business day before the input date * @throws IllegalArgumentException if the calculation is outside the supported range */ public default LocalDate previous(LocalDate date) { LocalDate previous = plusDays(date, -1); return isHoliday(previous) ? previous(previous) : previous; }
public void test_plusDays99() { LocalDate date = LocalDate.of(2012, 1, 1); for (int i = 0; i < 366 * 4; i++) { assertEquals(LocalDateUtils.plusDays(date, 99), date.plusDays(99)); date = date.plusDays(1); } }
public void test_plusDays0() { LocalDate date = LocalDate.of(2012, 1, 1); for (int i = 0; i < 366 * 4; i++) { assertEquals(LocalDateUtils.plusDays(date, 0), date.plusDays(0)); date = date.plusDays(1); } }
public void test_plusDays1() { LocalDate date = LocalDate.of(2012, 1, 1); for (int i = 0; i < 366 * 4; i++) { assertEquals(LocalDateUtils.plusDays(date, 1), date.plusDays(1)); date = date.plusDays(1); } }
public void test_plusDays3() { LocalDate date = LocalDate.of(2012, 1, 1); for (int i = 0; i < 366 * 4; i++) { assertEquals(LocalDateUtils.plusDays(date, 3), date.plusDays(3)); date = date.plusDays(1); } }
public void test_plusDaysM1() { LocalDate date = LocalDate.of(2012, 1, 1); for (int i = 0; i < 366 * 4; i++) { assertEquals(LocalDateUtils.plusDays(date, -1), date.plusDays(-1)); date = date.plusDays(1); } }
/** * Adds this tenor to the specified date. * <p> * This method implements {@link TemporalAmount}. * It is not intended to be called directly. * Use {@link LocalDate#plus(TemporalAmount)} instead. * * @param temporal the temporal object to add to * @return the result with this tenor added * @throws DateTimeException if unable to add * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal addTo(Temporal temporal) { // special case for performance if (temporal instanceof LocalDate) { LocalDate date = (LocalDate) temporal; return plusDays(date.plusMonths(period.toTotalMonths()), period.getDays()); } return period.addTo(temporal); }
/** * Subtracts this tenor from the specified date. * <p> * This method implements {@link TemporalAmount}. * It is not intended to be called directly. * Use {@link LocalDate#minus(TemporalAmount)} instead. * * @param temporal the temporal object to subtract from * @return the result with this tenor subtracted * @throws DateTimeException if unable to subtract * @throws ArithmeticException if numeric overflow occurs */ @Override public Temporal subtractFrom(Temporal temporal) { // special case for performance if (temporal instanceof LocalDate) { LocalDate date = (LocalDate) temporal; return plusDays(date.minusMonths(period.toTotalMonths()), -period.getDays()); } return period.subtractFrom(temporal); }
/** * Resolves this adjustment using the specified reference data, returning an adjuster. * <p> * This returns a {@link DateAdjuster} that performs the same calculation as this adjustment. * It binds the holiday calendar, looked up from the reference data, into the result. * As such, there is no need to pass the reference data in again. * <p> * The resulting adjuster will be {@link #normalized() normalized}. * * @param refData the reference data, used to find the holiday calendar * @return the adjuster, bound to a specific holiday calendar */ @Override public DateAdjuster resolve(ReferenceData refData) { HolidayCalendar holCalAdj = adjustment.getCalendar().resolve(refData); if (calendar == HolidayCalendarIds.NO_HOLIDAYS) { BusinessDayConvention adjustmentConvention = adjustment.getConvention(); return date -> adjustmentConvention.adjust(LocalDateUtils.plusDays(date, days), holCalAdj); } HolidayCalendar holCalAdd = calendar.resolve(refData); BusinessDayConvention adjustmentConvention = adjustment.getConvention(); return date -> adjustmentConvention.adjust(holCalAdd.shift(date, days), holCalAdj); }