public List getHolidays()

in jbpm/jbpm-flow/src/main/java/org/jbpm/process/core/timer/CalendarBean.java [255:350]


    public List<BusinessCalendarImpl.TimePeriod> getHolidays() {
        if (!calendarConfiguration.containsKey(HOLIDAYS)) {
            return Collections.emptyList();
        }
        String timezone = calendarConfiguration.getProperty(TIMEZONE);

        String holidaysString = calendarConfiguration.getProperty(HOLIDAYS);
        List<BusinessCalendarImpl.TimePeriod> holidays = new ArrayList<>();
        int currentYear = Calendar.getInstance().get(Calendar.YEAR);
        String[] hPeriods = holidaysString.split(",");

        for (String hPeriod : hPeriods) {
            boolean addNextYearHolidays = false;

            String[] fromTo = hPeriod.split(":");
            if (fromTo[0].startsWith("*")) {
                addNextYearHolidays = true;

                fromTo[0] = fromTo[0].replaceFirst("\\*", currentYear + "");
            }
            try {
                if (fromTo.length == 2) {
                    Calendar tmpFrom = new GregorianCalendar();
                    if (timezone != null) {
                        tmpFrom.setTimeZone(TimeZone.getTimeZone(timezone));
                    }
                    tmpFrom.setTime(getFormattedDate(fromTo[0], calendarConfiguration));

                    if (fromTo[1].startsWith("*")) {

                        fromTo[1] = fromTo[1].replaceFirst("\\*", currentYear + "");
                    }

                    Calendar tmpTo = new GregorianCalendar();
                    if (timezone != null) {
                        tmpTo.setTimeZone(TimeZone.getTimeZone(timezone));
                    }
                    tmpTo.setTime(getFormattedDate(fromTo[1], calendarConfiguration));
                    Date from = tmpFrom.getTime();

                    tmpTo.add(Calendar.DAY_OF_YEAR, 1);

                    if ((tmpFrom.get(Calendar.MONTH) > tmpTo.get(Calendar.MONTH)) && (tmpFrom.get(Calendar.YEAR) == tmpTo.get(Calendar.YEAR))) {
                        tmpTo.add(Calendar.YEAR, 1);
                    }

                    Date to = tmpTo.getTime();
                    holidays.add(new BusinessCalendarImpl.TimePeriod(from, to));

                    if (addNextYearHolidays) {
                        tmpFrom = new GregorianCalendar();
                        if (timezone != null) {
                            tmpFrom.setTimeZone(TimeZone.getTimeZone(timezone));
                        }
                        tmpFrom.setTime(getFormattedDate(fromTo[0], calendarConfiguration));
                        tmpFrom.add(Calendar.YEAR, 1);

                        from = tmpFrom.getTime();
                        tmpTo = new GregorianCalendar();
                        if (timezone != null) {
                            tmpTo.setTimeZone(TimeZone.getTimeZone(timezone));
                        }
                        tmpTo.setTime(getFormattedDate(fromTo[1], calendarConfiguration));
                        tmpTo.add(Calendar.YEAR, 1);
                        tmpTo.add(Calendar.DAY_OF_YEAR, 1);

                        if ((tmpFrom.get(Calendar.MONTH) > tmpTo.get(Calendar.MONTH)) && (tmpFrom.get(Calendar.YEAR) == tmpTo.get(Calendar.YEAR))) {
                            tmpTo.add(Calendar.YEAR, 1);
                        }

                        to = tmpTo.getTime();
                        holidays.add(new BusinessCalendarImpl.TimePeriod(from, to));
                    }
                } else {

                    Calendar c = new GregorianCalendar();
                    c.setTime(getFormattedDate(fromTo[0], calendarConfiguration));
                    c.add(Calendar.DAY_OF_YEAR, 1);
                    // handle one day holiday
                    holidays.add(new BusinessCalendarImpl.TimePeriod(getFormattedDate(fromTo[0], calendarConfiguration), c.getTime()));
                    if (addNextYearHolidays) {
                        Calendar tmp = Calendar.getInstance();
                        tmp.setTime(getFormattedDate(fromTo[0], calendarConfiguration));
                        tmp.add(Calendar.YEAR, 1);

                        Date from = tmp.getTime();
                        c.add(Calendar.YEAR, 1);
                        holidays.add(new BusinessCalendarImpl.TimePeriod(from, c.getTime()));
                    }
                }
            } catch (Exception e) {
                logger.error("Error while parsing holiday in business calendar", e);
            }
        }
        return holidays;
    }