@Test(dataProvider = "convention") public void test_convention(PeriodAdditionConvention convention, LocalDate input, int months, LocalDate expected) { assertEquals(convention.adjust(input, Period.ofMonths(months), HolidayCalendars.SAT_SUN), expected); }
/** * 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. * * @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 holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return date -> bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
@Test(dataProvider = "types") public void test_null(PeriodAdditionConvention type) { assertThrowsIllegalArg(() -> type.adjust(null, Period.ofMonths(3), HolidayCalendars.NO_HOLIDAYS)); assertThrowsIllegalArg(() -> type.adjust(date(2014, 7, 11), null, HolidayCalendars.NO_HOLIDAYS)); assertThrowsIllegalArg(() -> type.adjust(date(2014, 7, 11), Period.ofMonths(3), null)); assertThrowsIllegalArg(() -> type.adjust(null, null, null)); }
/** * Adjusts the date, adding the period and then applying the business day adjustment. * <p> * The calculation is performed in two steps. * <p> * Step one, use {@link PeriodAdditionConvention#adjust(LocalDate, Period, HolidayCalendar)} to add the period. * <p> * Step two, use {@link BusinessDayAdjustment#adjust(LocalDate, ReferenceData)} to adjust the result of step one. * * @param date the date to adjust * @param refData the reference data, used to find the holiday calendar * @return the adjusted date */ public LocalDate adjust(LocalDate date, ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }
/** * Adjusts the date, adding the tenor and then applying the business day adjustment. * <p> * The calculation is performed in two steps. * <p> * Step one, use {@link PeriodAdditionConvention#adjust(LocalDate, Period, HolidayCalendar)} to add the period. * <p> * Step two, use {@link BusinessDayAdjustment#adjust(LocalDate, ReferenceData)} to adjust the result of step one. * * @param date the date to adjust * @param refData the reference data, used to find the holiday calendar * @return the adjusted date */ public LocalDate adjust(LocalDate date, ReferenceData refData) { HolidayCalendar holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); return bda.adjust(additionConvention.adjust(date, tenor.getPeriod(), holCal), holCal); }
/** * 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. * * @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 holCal = adjustment.getCalendar().resolve(refData); BusinessDayConvention bda = adjustment.getConvention(); Period period = tenor.getPeriod(); return date -> bda.adjust(additionConvention.adjust(date, period, holCal), holCal); }