private void validateFrequency() { if (frequency == null) { throw new IllegalArgumentException( "A recurrence rule MUST contain a FREQ rule part."); } if (SECONDLY.equals(getFrequency())) { calIncField = Calendar.SECOND; } else if (MINUTELY.equals(getFrequency())) { calIncField = Calendar.MINUTE; } else if (HOURLY.equals(getFrequency())) { calIncField = Calendar.HOUR_OF_DAY; } else if (DAILY.equals(getFrequency())) { calIncField = Calendar.DAY_OF_YEAR; } else if (WEEKLY.equals(getFrequency())) { calIncField = Calendar.WEEK_OF_YEAR; } else if (MONTHLY.equals(getFrequency())) { calIncField = Calendar.MONTH; } else if (YEARLY.equals(getFrequency())) { calIncField = Calendar.YEAR; } else { throw new IllegalArgumentException("Invalid FREQ rule part '" + frequency + "' in recurrence rule"); } }
/** * Increments the specified calendar according to the frequency and interval specified in this recurrence rule. * * @param cal a java.util.Calendar to increment */ private void increment(final Calendar cal) { // initialise interval.. final int calInterval = (getInterval() >= 1) ? getInterval() : 1; cal.add(calIncField, calInterval); }
/** * {@inheritDoc} */ public final void setValue(final String aValue) throws ParseException { recur = new Recur(aValue); }
private Frequency deriveFilterType() { if (frequency == Frequency.DAILY || !getYearDayList().isEmpty() || !getMonthDayList().isEmpty()) { return Frequency.DAILY; } else if (frequency == Frequency.WEEKLY || !getWeekNoList().isEmpty()) { return Frequency.WEEKLY; } else if (frequency == Frequency.MONTHLY || !getMonthList().isEmpty()) { return Frequency.MONTHLY; } else if (frequency == Frequency.YEARLY) { return Frequency.YEARLY; } return null; }
outField(jgen, "freq", r.getFrequency()); outField(jgen, "wkst", r.getWeekStartDay().name()); if (r.getUntil() != null) { outField(jgen, "until", r.getUntil().toString()); outField(jgen, "count", r.getCount()); if (r.getInterval() > 1) { outField(jgen, "interval", r.getInterval()); outField(jgen, "bymonth", r.getMonthList()); outField(jgen, "byweekno", r.getWeekNoList()); outField(jgen, "byyearday", r.getYearDayList()); outField(jgen, "bymonthday", r.getMonthDayList()); outField(jgen, "byday", r.getDayList()); outField(jgen, "byhour", r.getHourList()); outField(jgen, "byminute", r.getMinuteList()); outField(jgen, "bysecond", r.getSecondList()); outField(jgen, "bysetpos", r.getSetPosList());
if (!getMonthList().isEmpty()) { b.append(';'); b.append(BYMONTH); if (!getWeekNoList().isEmpty()) { b.append(';'); b.append(BYWEEKNO); if (!getYearDayList().isEmpty()) { b.append(';'); b.append(BYYEARDAY); if (!getMonthDayList().isEmpty()) { b.append(';'); b.append(BYMONTHDAY); if (!getDayList().isEmpty()) { b.append(';'); b.append(BYDAY); if (!getHourList().isEmpty()) { b.append(';'); b.append(BYHOUR); if (!getMinuteList().isEmpty()) { b.append(';'); b.append(BYMINUTE); if (!getSecondList().isEmpty()) {
int freqCount = 0; for (Recur recur : recurList) { monthList.addAll(recur.getMonthList()); monthDayList.addAll(recur.getMonthDayList()); weekDayList.addAll(recur.getDayList()); hourList.addAll(recur.getHourList()); minuteList.addAll(recur.getMinuteList()); if (recur.getInterval() != 0) { freq = recur.getFrequency(); freqCount = recur.getInterval(); throw new IllegalStateException("Unable to convert intersection"); Recur newRecur = new Recur(freq, 0); if (freqCount != 0) { newRecur.setInterval(freqCount); newRecur.getMonthList().addAll(monthList); newRecur.getMonthDayList().addAll(monthDayList); newRecur.getDayList().addAll(weekDayList); newRecur.getHourList().addAll(hourList); newRecur.getMinuteList().addAll(minuteList); return newRecur;
final Calendar cal = getCalendarInstance(seed, true); if (getCount() < 1) { final Calendar seededCal = (Calendar) cal.clone(); while (seededCal.getTime().before(startDate)) { cal.setTime(seededCal.getTime()); increment(seededCal); final Date candidateSeed = Dates.getInstance(cal.getTime(), value); if (getUntil() != null && candidate != null && candidate.after(getUntil())) { break; if (getCount() > 0 && invalidCandidateCount >= getCount()) { break; final DateList candidates = getCandidates(candidateSeed, value); if (!candidates.isEmpty()) { noCandidateIncrementCount = 0; } else if (getCount() > 0 && invalidCandidateCount >= getCount()) { break; } else if (!(getUntil() != null && candidate.after(getUntil()))) { return candidate; increment(cal);
final Calendar cal = getCalendarInstance(date, true); final DateList days = new DateList(type); if (date instanceof DateTime) { if (DAILY.equals(getFrequency())) { if (cal.get(Calendar.DAY_OF_WEEK) == calDay) { days.add(Dates.getInstance(cal.getTime(), type)); } else if (WEEKLY.equals(getFrequency()) || !getWeekNoList().isEmpty()) { final int weekNo = cal.get(Calendar.WEEK_OF_YEAR); } else if (MONTHLY.equals(getFrequency()) || !getMonthList().isEmpty()) { final int month = cal.get(Calendar.MONTH); cal.add(Calendar.DAY_OF_MONTH, Dates.DAYS_PER_WEEK); } else if (YEARLY.equals(getFrequency())) { final int year = cal.get(Calendar.YEAR); return getOffsetDates(days, weekDay.getOffset());
/** * Applies BYDAY rules specified in this Recur instance to the specified date list. If no BYDAY rules are specified * the date list is returned unmodified. * * @param dates * @return */ private DateList getDayVariants(final DateList dates) { if (getDayList().isEmpty()) { return dates; } final DateList weekDayDates = getDateListInstance(dates); for (final Date date : dates) { for (final WeekDay weekDay : getDayList()) { // if BYYEARDAY or BYMONTHDAY is specified filter existing // list.. if (!getYearDayList().isEmpty() || !getMonthDayList().isEmpty()) { final Calendar cal = getCalendarInstance(date, true); if (weekDay.equals(WeekDay.getWeekDay(cal))) { weekDayDates.add(date); } } else { weekDayDates.addAll(getAbsWeekDays(date, dates.getType(), weekDay)); } } } return weekDayDates; }
/** * @throws ParseException */ public void testRecurrenceString() throws ParseException { Recur recur = new Recur(recurrenceString); assertEquals(expectedFrequency, recur.getFrequency()); assertEquals(expectedInterval, recur.getInterval()); assertEquals(expectedDayList, recur.getDayList()); }
switch (rRule.getRecur().getFrequency()) { case "DAILY": { if (rRule.getRecur().getInterval() == -1) { msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.everyDay"); } else //ALLE ... msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.allDay", rRule.getRecur().getInterval()); if (rRule.getRecur().getInterval() == -1) { msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.everyWeek"); } else //ALLE ... msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.allWeeks", rRule.getRecur().getInterval()); if (rRule.getRecur().getInterval() == -1) { msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.everyMonth"); } else //ALLE ... msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.allMonth", rRule.getRecur().getInterval()); if (rRule.getRecur().getInterval() == -1) { msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.everyYear"); } else //ALLE ... msg = I18nHelper.getLocalizedMessage("plugins.teamcal.event.event.allYear", rRule.getRecur().getInterval()); if (rRule.getRecur().getUntil() != null) { SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.YYYY", ThreadLocalUserContext.getLocale());
final Recur recur = new Recur(); recur.setInterval(recurrenceData.getInterval()); recur.setFrequency(ICal4JUtils.getCal4JFrequencyString(recurrenceData.getFrequency())); if (weekdays[i]) { if (i == 0) { recur.getDayList().add(WeekDay.MO); } else if (i == 1) { recur.getDayList().add(WeekDay.TU); } else if (i == 2) { recur.getDayList().add(WeekDay.WE); } else if (i == 3) { recur.getDayList().add(WeekDay.TH); } else if (i == 4) { recur.getDayList().add(WeekDay.FR); } else if (i == 5) { recur.getDayList().add(WeekDay.SA); } else if (i == 6) { recur.getDayList().add(WeekDay.SU); for (int i = 0; i < 31; i++) { if (monthdays[i]) { recur.getMonthDayList().add(i + 1); WeekDayList weekDays = ICal4JUtils.getDayListForRecurrenceFrequencyModeTwo(recurrenceData.getModeTwoMonth()); for (WeekDay weekDay : weekDays) { recur.getDayList().add(new WeekDay(weekDay, offset)); for (int i = 0; i < 12; i++) {
recurrenceData.setInterval(recur.getInterval() == -1 ? 1 : recur.getInterval()); for (WeekDay wd : recur.getDayList()) { recurrenceData.setCustomized(true); if (wd.getDay() == WeekDay.MO.getDay()) { recurrenceData.setMonthMode(RecurrenceMonthMode.NONE); boolean[] monthdays = recurrenceData.getMonthdays(); for (Integer day : recur.getMonthDayList()) { recurrenceData.setCustomized(true); recurrenceData.setMonthMode(RecurrenceMonthMode.EACH); if (recur.getDayList().size() == 1) { offset = recur.getDayList().get(0).getOffset(); } else if (recur.getDayList().size() > 1 && recur.getSetPosList().size() != 0) { offset = recur.getSetPosList().get(0); if (recur.getDayList().size() != 0) { recurrenceData.setCustomized(true); recurrenceData.setMonthMode(RecurrenceMonthMode.ATTHE); recurrenceData.setModeOneMonth(ICal4JUtils.getRecurrenceFrequencyModeOneByOffset(offset)); recurrenceData.setModeTwoMonth(ICal4JUtils.getRecurrenceFrequencyModeTwoForDay(recur.getDayList())); for (Integer day : recur.getMonthList()) { recurrenceData.setCustomized(true); if (recur.getDayList().size() == 1) { offset = recur.getDayList().get(0).getOffset(); } else if (recur.getDayList().size() > 1 && recur.getSetPosList().size() != 0) {
Calendar cal = getCalendarInstance(seed, true); final Calendar rootSeed = (Calendar)cal.clone(); while (seededCal.getTime().before(periodStart)) { cal.setTime(seededCal.getTime()); seededCal = smartIncrement(seededCal); if (seededCal == null) { return dates; if (getUntil() != null && candidate != null && candidate.after(getUntil())) { break; if (getCount() >= 1 && (dates.size() + invalidCandidates.size()) >= getCount()) { break; final DateList candidates = getCandidates(rootSeed, candidateSeed, value); if (!candidates.isEmpty()) { noCandidateIncrementCount = 0; || candidate.after(periodEnd)) { invalidCandidates.add(candidate); } else if (getCount() >= 1 && (dates.size() + invalidCandidates.size()) >= getCount()) { break; } else if (!candidate.before(periodStart) && !candidate.after(periodEnd) && (getUntil() == null || !candidate.after(getUntil()))) {
/** * Returns a list of start dates in the specified period represented by this recur. Any date fields not specified by * this recur are retained from the period start, and as such you should ensure the period start is initialised * correctly. * @param periodStart the start of the period * @param periodEnd the end of the period * @param value the type of dates to generate (i.e. date/date-time) * @return a list of dates */ public final DateList getDates(final Date periodStart, final Date periodEnd, final Value value) { return getDates(periodStart, periodStart, periodEnd, value, -1); }
private void testRRule(final TimeZone timeZone) { TeamEventDO event = createEvent(timeZone, "2012-12-21 8:30", "2012-12-21 9:00", null, 1, null, null); assertNull(event.getRecurrenceObject()); event = createEvent(timeZone, "2012-12-21 8:30", "2012-12-21 9:00", RecurrenceFrequency.WEEKLY, 1, null, null); assertEquals("FREQ=WEEKLY;INTERVAL=1", event.getRecurrenceRule()); Collection<TeamEvent> events = getRecurrenceEvents("2012-12-01", "2013-01-31", timeZone, event); assertEvents(events, timeZone, "2012-12-21 08:30", "2012-12-28 08:30", "2013-01-04 08:30", "2013-01-11 08:30", "2013-01-18 08:30", "2013-01-25 08:30"); String untilInTimeZone = "2013-01-31"; if (timeZone.getRawOffset() < 0) { untilInTimeZone = "2013-02-01"; } event = createEvent(timeZone, "2012-12-21 18:30", "2012-12-22 9:00", RecurrenceFrequency.WEEKLY, 2, "2013-01-31", untilInTimeZone); RRule rRule = event.getRecurrenceRuleObject(); final String utcString = DateHelper.formatIsoDate(rRule.getRecur().getUntil(), DateHelper.UTC); assertEquals("WEEKLY", rRule.getRecur().getFrequency()); assertEquals(untilInTimeZone, utcString); assertEquals(2, rRule.getRecur().getInterval()); events = getRecurrenceEvents("2012-12-01", "2013-03-31", timeZone, event); assertEvents(events, timeZone, "2012-12-21 18:30", "2013-01-04 18:30", "2013-01-18 18:30"); assertTrue(events.iterator().next() instanceof TeamEventDO); }
/** * Applies BYMONTH rules specified in this Recur instance to the specified date list. If no BYMONTH rules are * specified the date list is returned unmodified. * * @param dates * @return */ private DateList getMonthVariants(final DateList dates) { if (getMonthList().isEmpty()) { return dates; } final DateList monthlyDates = getDateListInstance(dates); for (final Date date : dates) { final Calendar cal = getCalendarInstance(date, true); final Calendar freqEnd = getCalendarInstance(date, true); increment(freqEnd); for (final Integer month : getMonthList()) { // Java months are zero-based.. // cal.set(Calendar.MONTH, month.intValue() - 1); cal.roll(Calendar.MONTH, (month - 1) - cal.get(Calendar.MONTH)); if (cal.after(freqEnd)) { break; // Do not break out of the FREQ-defined boundary } monthlyDates.add(Dates.getInstance(cal.getTime(), monthlyDates.getType())); } } return monthlyDates; }
/** * Applies BYMONTHDAY rules specified in this Recur instance to the specified date list. If no BYMONTHDAY rules are * specified the date list is returned unmodified. * * @param dates * @return */ private DateList getMonthDayVariants(final DateList dates) { if (getMonthDayList().isEmpty()) { return dates; } final DateList monthDayDates = getDateListInstance(dates); for (final Date date : dates) { final Calendar cal = getCalendarInstance(date, false); for (final Integer monthDay : getMonthDayList()) { try { cal.set(Calendar.DAY_OF_MONTH, Dates.getAbsMonthDay(cal.getTime(), monthDay)); monthDayDates.add(Dates.getInstance(cal.getTime(), monthDayDates.getType())); } catch (IllegalArgumentException iae) { if (log.isTraceEnabled()) { log.trace("Invalid day of month: " + Dates.getAbsMonthDay(cal .getTime(), monthDay)); } } } } return monthDayDates; }