net.fortuna.ical4j.model.Recur Java Examples

The following examples show how to use net.fortuna.ical4j.model.Recur. 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: ICal4JUtils.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param recur
 * @return
 */
public static RecurrenceFrequency getFrequency(final Recur recur)
{
  if (recur == null) {
    return null;
  }
  final String freq = recur.getFrequency();
  if (Recur.WEEKLY.equals(freq) == true) {
    return RecurrenceFrequency.WEEKLY;
  } else if (Recur.MONTHLY.equals(freq) == true) {
    return RecurrenceFrequency.MONTHLY;
  } else if (Recur.DAILY.equals(freq) == true) {
    return RecurrenceFrequency.DAILY;
  } else if (Recur.YEARLY.equals(freq) == true) {
    return RecurrenceFrequency.YEARLY;
  }
  return null;
}
 
Example #2
Source File: ThisAndFutureHelper.java    From cosmo with Apache License 2.0 6 votes vote down vote up
private void modifyOldSeries(NoteItem oldSeries, Date lastRecurrenceId) {
    EventStamp event = StampUtils.getEventStamp(oldSeries);
  
    // We set the end date to 1 second before the begining of the next day
    java.util.Calendar untilDateCalendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    untilDateCalendar.setTime(lastRecurrenceId);
    untilDateCalendar.add(java.util.Calendar.DAY_OF_MONTH, -1);
    untilDateCalendar.set(java.util.Calendar.HOUR_OF_DAY, 23);
    untilDateCalendar.set(java.util.Calendar.MINUTE, 59);
    untilDateCalendar.set(java.util.Calendar.SECOND, 59);
    Date untilDate = Dates.getInstance(untilDateCalendar.getTime(), lastRecurrenceId);
    
    // UNTIL must be UTC according to spec
    if(untilDate instanceof DateTime) {
        ((DateTime) untilDate).setUtc(true);
    }
    List<Recur> recurs = event.getRecurrenceRules();
    for (Recur recur : recurs) {
        recur.setUntil(untilDate);
    }
    
    // TODO: Figure out what to do with RDATEs
}
 
Example #3
Source File: CalendarEntry.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * @param rule
 * @return date of recurrence end
 */
public Date getRecurrenceEndDate() {
    final TimeZone tz = TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(java.util.Calendar.getInstance().getTimeZone().getID());

    if (recurrenceRule != null) {
        try {
            final Recur recur = new Recur(recurrenceRule);
            final Date dUntil = recur.getUntil();
            final DateTime dtUntil = dUntil == null ? null : new DateTime(dUntil.getTime());
            if (dtUntil != null) {
                dtUntil.setTimeZone(tz);
                return dtUntil;
            }
        } catch (final ParseException e) {
            log.error("cannot restore recurrence rule", e);
        }
    }

    return null;
}
 
Example #4
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 #5
Source File: CalendarEntry.java    From olat with Apache License 2.0 6 votes vote down vote up
/**
 * @param rule
 * @return date of recurrence end
 */
public Date getRecurrenceEndDate() {
    final TimeZone tz = TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(java.util.Calendar.getInstance().getTimeZone().getID());

    if (recurrenceRule != null) {
        try {
            final Recur recur = new Recur(recurrenceRule);
            final Date dUntil = recur.getUntil();
            final DateTime dtUntil = dUntil == null ? null : new DateTime(dUntil.getTime());
            if (dtUntil != null) {
                dtUntil.setTimeZone(tz);
                return dtUntil;
            }
        } catch (final ParseException e) {
            log.error("cannot restore recurrence rule", e);
        }
    }

    return null;
}
 
Example #6
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 #7
Source File: ICal4JUtils.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 
 * @param rruleString
 * @return null if rruleString is empty, otherwise new RRule object.
 */
public static RRule calculateRecurrenceRule(final String rruleString)
{
  if (StringUtils.isBlank(rruleString) == true) {
    return null;
  }
  try {
    final RRule rule = new RRule(rruleString);
    // set the recurrence end date to the last minute of the day
    final Recur recur = rule.getRecur();
    final net.fortuna.ical4j.model.Date until = recur != null ? recur.getUntil() : null;
    if (until != null) {
      final Date untilEndOfDay = CalendarUtils.getEndOfDay(until, PFUserContext.getTimeZone());
      recur.setUntil(new net.fortuna.ical4j.model.Date(untilEndOfDay));
    }
    return rule;
  } catch (final ParseException ex) {
    log.error("Exception encountered while parsing rrule '" + rruleString + "': " + ex.getMessage(), ex);
    return null;
  }
}
 
Example #8
Source File: StandardTriageStatusQueryProcessor.java    From cosmo with Apache License 2.0 6 votes vote down vote up
/**
 * 
 * @param es EventStamp
 * @param later boolean
 * @return Dur
 */
private Dur getDurToUseForExpanding(EventStamp es, boolean later) {
    List<Recur> rules = es.getRecurrenceRules();
    
    // No rules, assume RDATEs so expand a year
    if(rules.size()==0) {
        return later ? yearLaterDur : yearDoneDur;
    }
    
    // Look at first rule only
    Recur recur = rules.get(0);
    
    // If rule is yearly or monthly then expand a year,
    // otherwise only expand a month
    if(Recur.YEARLY.equals(recur.getFrequency()) ||
       Recur.MONTHLY.equals(recur.getFrequency())) {
        return later ? yearLaterDur : yearDoneDur;
    }
    else {
        return later ? monthLaterDur : monthDoneDur;
    }
}
 
Example #9
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(TemporalExpressions.MonthRange expr) {
    int startMonth = expr.getStartMonth();
    int endMonth = expr.getEndMonth();
    Calendar cal = Calendar.getInstance();
    int maxMonth = cal.getActualMaximum(Calendar.MONTH);
    NumberList monthList = new NumberList();
    monthList.add(startMonth + 1);
    while (startMonth != endMonth) {
        startMonth++;
        if (startMonth > maxMonth) {
            startMonth = Calendar.JANUARY;
        }
        monthList.add(startMonth + 1);
    }
    Recur recur = new Recur(Recur.MONTHLY, 0);
    recur.getMonthList().addAll(monthList);
    this.state.addRecur(recur);
}
 
Example #10
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 6 votes vote down vote up
@Override
public void visit(TemporalExpressions.DayOfWeekRange expr) {
    int startDay = expr.getStartDay();
    int endDay = expr.getEndDay();
    WeekDayList dayList = new WeekDayList();
    dayList.add(dayOfWeekArray[startDay - 1]);
    while (startDay != endDay) {
        startDay++;
        if (startDay > Calendar.SATURDAY) {
            startDay = Calendar.SUNDAY;
        }
        dayList.add(dayOfWeekArray[startDay - 1]);
    }
    Recur recur = new Recur(Recur.DAILY, 0);
    recur.getDayList().addAll(dayList);
    this.state.addRecur(recur);
}
 
Example #11
Source File: ICal4JUtils.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param recur
 * @return
 */
public static String getFrequency(final RecurrenceFrequency interval)
{
  if (interval == null) {
    return null;
  }
  if (interval == RecurrenceFrequency.WEEKLY) {
    return Recur.WEEKLY;
  } else if (interval == RecurrenceFrequency.DAILY) {
    return Recur.DAILY;
  } else if (interval == RecurrenceFrequency.MONTHLY) {
    return Recur.MONTHLY;
  } else if (interval == RecurrenceFrequency.YEARLY) {
    return Recur.YEARLY;
  }
  return null;
}
 
Example #12
Source File: TeamEventUtils.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
public static String calculateRRule(final TeamEventRecurrenceData recurData)
{
  if (recurData == null || recurData.getFrequency() == null || recurData.getFrequency() == RecurrenceFrequency.NONE) {
    return null;
  }
  if (recurData.isCustomized() == false) {
    recurData.setInterval(1);
  }
  final Recur recur = new Recur();
  final net.fortuna.ical4j.model.Date untilDate = ICal4JUtils.getICal4jDate(recurData.getUntil(), recurData.getTimeZone());
  if (untilDate != null) {
    recur.setUntil(untilDate);
  }
  recur.setInterval(recurData.getInterval());
  recur.setFrequency(ICal4JUtils.getCal4JFrequencyString(recurData.getFrequency()));
  final RRule rrule = new RRule(recur);
  return rrule.getValue();
}
 
Example #13
Source File: ICal4JUtilsTest.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void recurTests()
{
  final TimeZone timeZone = DateHelper.EUROPE_BERLIN;
  final Recur recur = new Recur();
  recur.setFrequency(ICal4JUtils.getCal4JFrequencyString(RecurrenceFrequency.WEEKLY));
  recur.setUntil(getDate("2013-01-31", timeZone));
  recur.setInterval(2);
  final DateList dateList = recur.getDates(getDate("2013-01-01", timeZone), getDate("2012-01-02", timeZone),
      getDate("2013-03-31", timeZone), Value.TIME);
  Assert.assertEquals(3, dateList.size());
  final DateFormat df = new SimpleDateFormat(DateFormats.ISO_TIMESTAMP_MINUTES);
  df.setTimeZone(timeZone);
  Assert.assertEquals("2013-01-01 00:00", df.format(dateList.get(0)));
  Assert.assertEquals("2013-01-15 00:00", df.format(dateList.get(1)));
  Assert.assertEquals("2013-01-29 00:00", df.format(dateList.get(2)));
}
 
Example #14
Source File: Calendar_EventRepeatMaster.java    From o2oa with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * 获取重复时间表达式中结束的日期
 * @return
 */
public Date getRecurrenceEndDate() {
	final TimeZone tz = TimeZoneRegistryFactory.getInstance().createRegistry()
			.getTimeZone(java.util.Calendar.getInstance().getTimeZone().getID());
	if (recurrenceRule != null) {
		try {
			final Recur recur = new Recur(recurrenceRule);
			final Date dUntil = recur.getUntil();
			final DateTime dtUntil = dUntil == null ? null : new DateTime(dUntil.getTime());
			if (dtUntil != null) {
				dtUntil.setTimeZone(tz);
				return dtUntil;
			}
		} catch (final ParseException e) {
			System.out.println("cannot restore recurrence rule");
			e.printStackTrace();
		}
	}
	return null;
}
 
Example #15
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 #16
Source File: MockBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Sets exception rules.
 * @param recurs The list.
 */
public void setExceptionRules(List<Recur> recurs) {
    if (recurs == null) {
        return;
    }
    PropertyList<Property> pl = getEvent().getProperties();
    for (Property exrule : pl.getProperties(Property.EXRULE)) {
        pl.remove(exrule);
    }
    for (Recur recur : recurs) {
        pl.add(new ExRule(recur));
    }
}
 
Example #17
Source File: ThisAndFutureHelperTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests break all day series.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testBreakAllDaySeries() throws Exception {
    Calendar cal1 = getCalendar("thisandfuturetest_allday.ics");
    Calendar cal2 = getCalendar("thisandfuturetest_allday_changed.ics");
    
    NoteItem oldSeries = createEvent("oldmaster", cal1);
    NoteItem newSeries = createEvent("newmaster", cal2);
    
    Date lastRecurrenceId = new Date("20070813");
    
    ThisAndFutureHelper helper = new ThisAndFutureHelper();
    
    Set<NoteItem> results = 
        helper.breakRecurringEvent(oldSeries, newSeries, lastRecurrenceId);
    
    EventStamp eventStamp = StampUtils.getEventStamp(oldSeries);
    Recur recur = eventStamp.getRecurrenceRules().get(0);
    
    Assert.assertEquals(new Date("20070812"), recur.getUntil());
    
    Assert.assertEquals(4, results.size());
    
    assertContains("oldmaster:20070820", results, false);
    assertContains("oldmaster:20070827", results, false);
    
    assertContains("newmaster:20070824", results, true);
    assertContains("newmaster:20070831", results, true);
}
 
Example #18
Source File: EventStampInterceptorTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Tests event stamp handler all day.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testEventStampHandlerAllDay() throws Exception {
    
    HibNoteItem master = new HibNoteItem();
    HibEventStamp eventStamp = new HibEventStamp(master);
    eventStamp.createCalendar();
    eventStamp.setStartDate(new Date("20070212"));
    eventStamp.setEndDate(new Date("20070213"));
    master.addStamp(eventStamp);
    
    HibEventTimeRangeIndex index = interceptor.calculateEventStampIndexes(eventStamp);
    
    Assert.assertEquals("20070212", index.getStartDate());
    Assert.assertEquals("20070213", index.getEndDate());
    Assert.assertTrue(index.getIsFloating().booleanValue());
  
    String recur1 = "FREQ=DAILY;";
    
    ArrayList<Recur> recursList = new ArrayList<Recur>();
    if (recur1 != null) {
        for (String s : recur1.split(":")) {
            try {
                recursList.add(new Recur(s));
            } catch (ParseException e) {
               
            }
        }
    }
    
    List<Recur> recurs = recursList;
    eventStamp.setRecurrenceRules(recurs);
    
    index = interceptor.calculateEventStampIndexes(eventStamp);
    
    Assert.assertEquals("20070212", index.getStartDate());
    Assert.assertEquals(HibEventStamp.TIME_INFINITY, index.getEndDate());
    Assert.assertTrue(index.getIsFloating().booleanValue());
}
 
Example #19
Source File: ThisAndFutureHelperTest.java    From cosmo with Apache License 2.0 5 votes vote down vote up
/**
 * Test break floating series.
 * @throws Exception - if something is wrong this exception is thrown.
 */
@Test
public void testBreakFloatingSeries() throws Exception {
    Calendar cal1 = getCalendar("thisandfuturetest_floating.ics");
    Calendar cal2 = getCalendar("thisandfuturetest_floating_changed.ics");
    
    NoteItem oldSeries = createEvent("oldmaster", cal1);
    NoteItem newSeries = createEvent("newmaster", cal2);
    
    Date lastRecurrenceId = new DateTime("20070808T081500");
    
    ThisAndFutureHelper helper = new ThisAndFutureHelper();
    
    Set<NoteItem> results = 
        helper.breakRecurringEvent(oldSeries, newSeries, lastRecurrenceId);
    
    EventStamp eventStamp = StampUtils.getEventStamp(oldSeries);
    Recur recur = eventStamp.getRecurrenceRules().get(0);
    
    Assert.assertEquals(new DateTime("20070807T235959Z"), recur.getUntil());
    
    Assert.assertEquals(8, results.size());
    
    assertContains("oldmaster:20070808T081500", results, false);
    assertContains("oldmaster:20070809T081500", results, false);
    assertContains("oldmaster:20070810T081500", results, false);
    assertContains("oldmaster:20070811T081500", results, false);
    assertContains("newmaster:20070808T081500", results, true);
    assertContains("newmaster:20070809T081500", results, true);
    assertContains("newmaster:20070810T081500", results, true);
    assertContains("newmaster:20070811T081500", results, true);
}
 
Example #20
Source File: ICal4JUtils.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public static Date calculateRecurrenceUntil(final String rruleString)
{
  if (StringUtils.isBlank(rruleString) == true) {
    return null;
  }
  final Recur recur = calculateRecurrence(rruleString);
  if (recur == null) {
    return null;
  }
  return recur.getUntil();
}
 
Example #21
Source File: ICal4JUtils.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public static String getCal4JFrequencyString(final RecurrenceFrequency interval)
{
  if (interval == RecurrenceFrequency.DAILY) {
    return Recur.DAILY;
  } else if (interval == RecurrenceFrequency.WEEKLY) {
    return Recur.WEEKLY;
  } else if (interval == RecurrenceFrequency.MONTHLY) {
    return Recur.MONTHLY;
  } else if (interval == RecurrenceFrequency.YEARLY) {
    return Recur.YEARLY;
  }
  return null;
}
 
Example #22
Source File: TeamEventDO.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Will be renewed if {@link #setRecurrenceRule(String)} is called.
 * @return the recurrenceRuleObject
 */
@Transient
public Recur getRecurrenceObject()
{
  final RRule rrule = getRecurrenceRuleObject();
  return rrule != null ? rrule.getRecur() : null;
}
 
Example #23
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 #24
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(TemporalExpressions.DayOfMonthRange expr) {
    int startDay = expr.getStartDay();
    int endDay = expr.getEndDay();
    NumberList dayList = new NumberList();
    dayList.add(startDay);
    while (startDay != endDay) {
        startDay++;
        dayList.add(startDay);
    }
    Recur recur = new Recur(Recur.DAILY, 0);
    recur.getMonthDayList().addAll(dayList);
    this.state.addRecur(recur);
}
 
Example #25
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public List<Recur> getRecurrenceRules() {
    List<Recur> toReturn = new ArrayList<>();
    VEvent event = getEvent();
    if(event != null) {
        PropertyList<RRule> rruleProperties = event.getProperties().getProperties(Property.RRULE);
        for (RRule rrule : rruleProperties) {
            toReturn.add(rrule.getRecur());
        }
    }
    return toReturn;
}
 
Example #26
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void setRecurrenceRules(List<Recur> recurs) {
    if (recurs == null) {
        return;
    }
    PropertyList<Property> properties = getEvent().getProperties();
    for (Property rrule : properties.getProperties(Property.RRULE)) {
        properties.remove(rrule);
    }
    for (Recur recur : recurs) {
        properties.add(new RRule(recur));
    }      
}
 
Example #27
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void setRecurrenceRule(Recur recur) {
    if (recur == null) {
        return;
    }
    ArrayList<Recur> recurs = new ArrayList<Recur>(1);
    recurs.add(recur);
    setRecurrenceRules(recurs);
}
 
Example #28
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public List<Recur> getExceptionRules() {
    List<Recur> toReturn = new ArrayList<Recur>();
    PropertyList<ExRule> exRuleProperties = getEvent().getProperties().getProperties(Property.EXRULE);
    for (ExRule exrule : exRuleProperties) {
        toReturn.add(exrule.getRecur());
    }
    return toReturn;
}
 
Example #29
Source File: HibBaseEventStamp.java    From cosmo with Apache License 2.0 5 votes vote down vote up
public void setExceptionRules(List<Recur> recurs) {
    if (recurs == null) {
        return;
    }
    PropertyList<Property> properties = getEvent().getProperties();
    for (Property exrule : properties.getProperties(Property.EXRULE)) {
        properties.remove(exrule);
    }
    for (Recur recur : recurs) {
        properties.add(new ExRule(recur));
    }
}
 
Example #30
Source File: ICalRecurConverter.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
public void addRecur(Recur recur) {
    if (this.isIntersection) {
        if (this.isExcluded) {
            this.exRecurList.add(recur);
        } else {
            this.inclRecurList.add(recur);
        }
    } else {
        if (this.isExcluded) {
            exRuleList.add(new ExRule(recur));
        } else {
            incRuleList.add(new RRule(recur));
        }
    }
}