Java Code Examples for net.fortuna.ical4j.model.Recur#getInterval()

The following examples show how to use net.fortuna.ical4j.model.Recur#getInterval() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CalendarUtils.java    From olat with Apache License 2.0 6 votes vote down vote up
public static String getRecurrence(final String rule) {
    if (rule != null) {
        try {
            final Recur recur = new Recur(rule);
            final String frequency = recur.getFrequency();
            final WeekDayList wdl = recur.getDayList();
            final Integer interval = recur.getInterval();
            if ((wdl != null && wdl.size() > 0)) {
                // we only support one rule with daylist
                return CalendarEntry.WORKDAILY;
            } else if (interval != null && interval == 2) {
                // we only support one rule with interval
                return CalendarEntry.BIWEEKLY;
            } else {
                // native supportet rule
                return frequency;
            }
        } catch (final ParseException e) {
            log.error("cannot restore recurrence rule", e);
        }
    }

    return null;
}
 
Example 2
Source File: CalendarUtils.java    From olat with Apache License 2.0 6 votes vote down vote up
public static String getRecurrence(final String rule) {
    if (rule != null) {
        try {
            final Recur recur = new Recur(rule);
            final String frequency = recur.getFrequency();
            final WeekDayList wdl = recur.getDayList();
            final Integer interval = recur.getInterval();
            if ((wdl != null && wdl.size() > 0)) {
                // we only support one rule with daylist
                return CalendarEntry.WORKDAILY;
            } else if (interval != null && interval == 2) {
                // we only support one rule with interval
                return CalendarEntry.BIWEEKLY;
            } else {
                // native supportet rule
                return frequency;
            }
        } catch (final ParseException e) {
            log.error("cannot restore recurrence rule", e);
        }
    }

    return null;
}
 
Example 3
Source File: TeamEventUtilsTest.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
private void assertRecurrence(final TeamEventDO event, final TimeZone timeZone, final RecurrenceFrequency frequency, final int interval,
    final String utcRecurrenceUntil)
{
  final Recur recur = event.getRecurrenceObject();
  if (frequency == null) {
    Assert.assertNull(recur);
    Assert.assertNull(event.getRecurrenceUntil());
    return;
  }
  Assert.assertEquals(frequency, ICal4JUtils.getFrequency(recur));
  if (recur.getInterval() > 1) {
    Assert.assertEquals(interval, recur.getInterval());
  } else {
    Assert.assertEquals(-1, recur.getInterval());
  }
  if (utcRecurrenceUntil == null) {
    Assert.assertNull(event.getRecurrenceUntil());
  } else {
    final String utcString = DateHelper.formatIsoDate(event.getRecurrenceUntil(), DateHelper.UTC);
    Assert.assertEquals(utcRecurrenceUntil, utcString);
  }
}
 
Example 4
Source File: TeamEventRecurrenceData.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public TeamEventRecurrenceData(final Recur recur, final TimeZone timeZone)
{
  this.timeZone = timeZone;
  if (recur == null) {
    return;
  }
  this.interval = recur.getInterval();
  if (this.interval < 1) {
    this.interval = 1;
  }
  if (recur.getUntil() != null) {
    this.until = CalendarUtils.getEndOfDay(recur.getUntil(), timeZone);
  }
  this.frequency = ICal4JUtils.getFrequency(recur);
}
 
Example 5
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 4 votes vote down vote up
protected Recur consolidateRecurs(List<Recur> recurList) {
    // Try to consolidate a list of Recur instances into one instance
    Set<Integer> monthList = new HashSet<>();
    Set<Integer> monthDayList = new HashSet<>();
    Set<WeekDay> weekDayList = new HashSet<>();
    Set<Integer> hourList = new HashSet<>();
    Set<Integer> minuteList = new HashSet<>();
    String freq = null;
    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();
        }
    }
    if (freq == null && monthList.size() > 0) {
        freq = Recur.MONTHLY;
    } else if (freq == null && (monthDayList.size() > 0 || weekDayList.size() > 0)) {
        freq = Recur.DAILY;
    } else if (freq == null && hourList.size() > 0) {
        freq = Recur.HOURLY;
    } else if (freq == null && minuteList.size() > 0) {
        freq = Recur.MINUTELY;
    }
    if (freq == null) {
        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;
}