/** * Moves the day to the first/next occurrence of the weekday and direction specified * @param f the specification of the weekday and direction of movement * @param day the day to move * @return the day moved to the weekday and in the direction as specified */ private LocalDate moveDateToFirstOccurrenceOfWeekday(FixedWeekdayRelativeToFixed f, LocalDate day) { final DayOfWeek weekday = xmlUtil.getWeekday(f.getWeekday()); return day.with(f.getWhen() == When.AFTER ? next(weekday) : previous(weekday)); }
/** {@inheritDoc} */ @Override public void parse(int year, Set<Holiday> holidays, final Holidays config) { for (FixedWeekdayRelativeToFixed f : config.getFixedWeekdayRelativeToFixed()) { if (!isValid(f, year)) { continue; } LocalDate day = calendarUtil.create(year, f.getDay()); day = moveDateToFirstOccurrenceOfWeekday(f, day); int days = determineNumberOfDays(f); day = f.getWhen() == When.AFTER ? day.plusDays(days) : day.minusDays(days); HolidayType type = xmlUtil.getType(f.getLocalizedType()); holidays.add(new Holiday(day, f.getDescriptionPropertiesKey(), type)); } }