public void test_FRI_SAT_next() { assertEquals(HolidayCalendars.FRI_SAT.next(WED_2014_07_09), THU_2014_07_10); assertEquals(HolidayCalendars.FRI_SAT.next(THU_2014_07_10), SUN_2014_07_13); assertEquals(HolidayCalendars.FRI_SAT.next(FRI_2014_07_11), SUN_2014_07_13); assertEquals(HolidayCalendars.FRI_SAT.next(SAT_2014_07_12), SUN_2014_07_13); assertEquals(HolidayCalendars.FRI_SAT.next(SUN_2014_07_13), MON_2014_07_14); }
@Override public LocalDate calculatePublicationFromFixing(LocalDate fixingDate, ReferenceData refData) { HolidayCalendar fixingCal = fixingCalendar.resolve(refData); return fixingCal.shift(fixingCal.nextOrSame(fixingDate), publicationDateOffset); }
@Override public LocalDate adjust(LocalDate date, HolidayCalendar calendar) { if (calendar.isBusinessDay(date)) { return date; } if (date.getDayOfWeek() == SUNDAY || date.getDayOfWeek() == MONDAY) { return calendar.next(date); } else { return calendar.previous(date); } } };
/** * Finds the previous business day, returning the input date if it is a business day. * <p> * Given a date, this method returns a business day. * If the input date is a business day, it is returned. * Otherwise, the previous business day is returned. * * @param date the date to adjust * @return the input date if it is a business day, or the previous business day * @throws IllegalArgumentException if the calculation is outside the supported range */ public default LocalDate previousOrSame(LocalDate date) { return isHoliday(date) ? previous(date) : date; }
/** * Finds the next business day, returning the input date if it is a business day. * <p> * Given a date, this method returns a business day. * If the input date is a business day, it is returned. * Otherwise, the next business day is returned. * * @param date the date to adjust * @return the input date if it is a business day, or the next business day * @throws IllegalArgumentException if the calculation is outside the supported range */ public default LocalDate nextOrSame(LocalDate date) { return isHoliday(date) ? next(date) : date; }
/** * Shifts the date by the specified number of business days. * <p> * If the amount is zero, the input date is returned. * If the amount is positive, later business days are chosen. * If the amount is negative, earlier business days are chosen. * * @param date the date to adjust * @param amount the number of business days to adjust by * @return the shifted date * @throws IllegalArgumentException if the calculation is outside the supported range */ public default LocalDate shift(LocalDate date, int amount) { LocalDate adjusted = date; if (amount > 0) { for (int i = 0; i < amount; i++) { adjusted = next(adjusted); } } else if (amount < 0) { for (int i = 0; i > amount; i--) { adjusted = previous(adjusted); } } return adjusted; }
@Override public LocalDate adjust(LocalDate date, HolidayCalendar calendar) { return calendar.nextOrSame(date); } },
public void test_NO_HOLIDAYS() { HolidayCalendar test = HolidayCalendars.NO_HOLIDAYS; LocalDateUtils.stream(LocalDate.of(2011, 1, 1), LocalDate.of(2015, 1, 31)).forEach(date -> { assertEquals(test.isBusinessDay(date), true); assertEquals(test.isHoliday(date), false); }); assertEquals(test.getName(), "NoHolidays"); assertEquals(test.toString(), "HolidayCalendar[NoHolidays]"); }
public void test_combineWith_satSun() { Iterable<LocalDate> holidays = Arrays.asList(WED_2014_07_16); ImmutableHolidayCalendar base = ImmutableHolidayCalendar.of(TEST_ID, holidays, SATURDAY, SUNDAY); HolidayCalendar test = base.combinedWith(HolidayCalendars.FRI_SAT); assertEquals(test.getName(), "Fri/Sat+Test1"); assertEquals(test.isHoliday(THU_2014_07_10), false); assertEquals(test.isHoliday(FRI_2014_07_11), true); assertEquals(test.isHoliday(SAT_2014_07_12), true); assertEquals(test.isHoliday(SUN_2014_07_13), true); assertEquals(test.isHoliday(MON_2014_07_14), false); assertEquals(test.isHoliday(TUE_2014_07_15), false); assertEquals(test.isHoliday(WED_2014_07_16), true); assertEquals(test.isHoliday(THU_2014_07_17), false); assertEquals(test.isHoliday(FRI_2014_07_18), true); assertEquals(test.isHoliday(SAT_2014_07_19), true); assertEquals(test.isHoliday(SUN_2014_07_20), true); assertEquals(test.isHoliday(MON_2014_07_21), false); }
/** * Finds the next business day within the month, returning the input date if it is a business day, * or the last business day of the month if the next business day is in a different month. * <p> * Given a date, this method returns a business day. * If the input date is a business day, it is returned. * If the next business day is within the same month, it is returned. * Otherwise, the last business day of the month is returned. * <p> * Note that the result of this method may be earlier than the input date. * <p> * This corresponds to the {@linkplain BusinessDayConventions#MODIFIED_FOLLOWING modified following} * business day convention. * * @param date the date to adjust * @return the input date if it is a business day, the next business day if within the same month * or the last business day of the month * @throws IllegalArgumentException if the calculation is outside the supported range */ public default LocalDate nextSameOrLastInMonth(LocalDate date) { LocalDate nextOrSame = nextOrSame(date); return (nextOrSame.getMonthValue() != date.getMonthValue() ? previous(date) : nextOrSame); }
public void test_THU_FRI_previous() { assertEquals(HolidayCalendars.THU_FRI.previous(THU_2014_07_10), WED_2014_07_09); assertEquals(HolidayCalendars.THU_FRI.previous(FRI_2014_07_11), WED_2014_07_09); assertEquals(HolidayCalendars.THU_FRI.previous(SAT_2014_07_12), WED_2014_07_09); assertEquals(HolidayCalendars.THU_FRI.previous(SUN_2014_07_13), SAT_2014_07_12); }
@Override public LocalDate adjust(LocalDate date, HolidayCalendar calendar) { LocalDate adjusted = calendar.previousOrSame(date); if (adjusted.getMonth() != date.getMonth()) { adjusted = calendar.next(date); } return adjusted; } },
private LocalDate shiftOutOfRange(LocalDate date, int amount) { if (date.getYear() >= 0 && date.getYear() < 10000) { return HolidayCalendar.super.shift(date, amount); } throw new IllegalArgumentException("Date is outside the accepted range (year 0000 to 10,000): " + date); }
@Override public LocalDate adjust(LocalDate date) { ArgChecker.notNull(date, "date"); LocalDate wed3 = date.with(TemporalAdjusters.dayOfWeekInMonth(3, DayOfWeek.WEDNESDAY)); return canada.previousOrSame(gblo.shift(wed3, -2)); } },
@Override public LocalDate adjust(LocalDate date, HolidayCalendar calendar) { return calendar.previousOrSame(date); } },
/** * Checks if the specified date is the last business day of the month. * <p> * This returns true if the date specified is the last valid business day of the month. * * @param date the date to check * @return true if the specified date is the last business day of the month * @throws IllegalArgumentException if the date is outside the supported range */ public default boolean isLastBusinessDayOfMonth(LocalDate date) { return isBusinessDay(date) && next(date).getMonthValue() != date.getMonthValue(); }
public void test_combinedWith() { HolidayCalendar base1 = new MockHolCal(); HolidayCalendar base2 = HolidayCalendars.FRI_SAT; HolidayCalendar test = base1.combinedWith(base2); assertEquals(test.toString(), "HolidayCalendar[Fri/Sat+Mock]"); assertEquals(test.getName(), "Fri/Sat+Mock"); assertEquals(test.equals(base1.combinedWith(base2)), true); assertEquals(test.equals(ANOTHER_TYPE), false); assertEquals(test.equals(null), false); assertEquals(test.hashCode(), base1.combinedWith(base2).hashCode()); assertEquals(test.isHoliday(THU_2014_07_10), false); assertEquals(test.isHoliday(FRI_2014_07_11), true); assertEquals(test.isHoliday(SAT_2014_07_12), true); assertEquals(test.isHoliday(SUN_2014_07_13), true); assertEquals(test.isHoliday(MON_2014_07_14), false); assertEquals(test.isHoliday(TUE_2014_07_15), false); assertEquals(test.isHoliday(WED_2014_07_16), true); assertEquals(test.isHoliday(THU_2014_07_17), false); assertEquals(test.isHoliday(FRI_2014_07_18), true); assertEquals(test.isHoliday(SAT_2014_07_19), true); assertEquals(test.isHoliday(SUN_2014_07_20), true); assertEquals(test.isHoliday(MON_2014_07_21), false); }
@Override public double yearFraction(LocalDate firstDate, LocalDate secondDate, ScheduleInfo scheduleInfo) { return calendar.daysBetween(firstDate, secondDate) / 252d; }
"Reference data not found for '{}' of type 'HolidayCalendarId' when finding '{}'", splitId, id)); cal = cal.combinedWith(splitCal);
@Test public void testImmutableReferenceDataWithMergedHolidays() { HolidayCalendar hc = HolidayCalendars.FRI_SAT.combinedWith(HolidayCalendars.SAT_SUN); ImmutableReferenceData referenceData = ImmutableReferenceData.of(hc.getId(), hc); LocalDate date = BusinessDayAdjustment.of(BusinessDayConventions.PRECEDING, hc.getId()).adjust(LocalDate.of(2016, 8, 20), referenceData); assertEquals(LocalDate.of(2016, 8, 18), date); }