Search in sources :

Example 6 with DateList

use of net.fortuna.ical4j.model.DateList in project OpenOLAT by OpenOLAT.

the class CalendarUtils method getRecurrenceExcludeDates.

/**
 * Create list with excluded dates based on the exclusion rule.
 * @param recurrenceExc
 * @return list with excluded dates
 */
public static List<Date> getRecurrenceExcludeDates(String recurrenceExc) {
    List<Date> recurExcDates = new ArrayList<>();
    if (recurrenceExc != null && !recurrenceExc.equals("")) {
        try {
            net.fortuna.ical4j.model.ParameterList pl = new net.fortuna.ical4j.model.ParameterList();
            ExDate exdate = new ExDate(pl, recurrenceExc);
            DateList dl = exdate.getDates();
            for (Object date : dl) {
                Date excDate = (Date) date;
                recurExcDates.add(excDate);
            }
        } catch (ParseException e) {
            log.error("cannot restore recurrence exceptions", e);
        }
    }
    return recurExcDates;
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate) ExDate(net.fortuna.ical4j.model.property.ExDate) ParseException(java.text.ParseException) DateList(net.fortuna.ical4j.model.DateList)

Example 7 with DateList

use of net.fortuna.ical4j.model.DateList in project bw-calendar-engine by Bedework.

the class IcalUtil method makeDateTimes.

/**
 * @param val
 * @return Collection
 * @throws Throwable
 */
public static Collection<BwDateTime> makeDateTimes(final DateListProperty val) throws Throwable {
    DateList dl = val.getDates();
    TreeSet<BwDateTime> ts = new TreeSet<BwDateTime>();
    Parameter par = getParameter(val, "VALUE");
    boolean isDateType = (par != null) && (par.equals(Value.DATE));
    String tzidval = null;
    Parameter tzid = getParameter(val, "TZID");
    if (tzid != null) {
        tzidval = tzid.getValue();
    }
    Iterator it = dl.iterator();
    while (it.hasNext()) {
        Date dt = (Date) it.next();
        ts.add(BwDateTime.makeBwDateTime(isDateType, dt.toString(), tzidval));
    }
    return ts;
}
Also used : BwDateTime(org.bedework.calfacade.BwDateTime) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) Parameter(net.fortuna.ical4j.model.Parameter) DateList(net.fortuna.ical4j.model.DateList) Date(net.fortuna.ical4j.model.Date)

Example 8 with DateList

use of net.fortuna.ical4j.model.DateList in project bw-calendar-engine by Bedework.

the class RecurUtil method getLastDate.

/* Return the highest possible start date from this recurrence or null
   * if no count or until date specified
   */
private static Date getLastDate(final Recur r, Date start, final Date maxRangeEnd) {
    Date seed = start;
    Date until = r.getUntil();
    if (until != null) {
        return until;
    }
    int count = r.getCount();
    if (count < 1) {
        return null;
    }
    Dur days100 = new Dur(100, 0, 0, 0);
    int counted = 0;
    while ((counted < count) && (start.before(maxRangeEnd))) {
        Date end = new DateTime(days100.getTime(start));
        DateList dl = r.getDates(seed, start, end, Value.DATE_TIME);
        int sz = dl.size();
        counted += sz;
        if (sz != 0) {
            until = (Date) dl.get(sz - 1);
        }
        start = end;
    }
    return until;
}
Also used : Dur(net.fortuna.ical4j.model.Dur) DateList(net.fortuna.ical4j.model.DateList) RDate(net.fortuna.ical4j.model.property.RDate) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 9 with DateList

use of net.fortuna.ical4j.model.DateList in project bw-calendar-engine by Bedework.

the class VEventUtil method makeDlp.

private static void makeDlp(final BwEvent val, final boolean exdt, final Collection<BwDateTime> dts, final PropertyList pl) throws Throwable {
    if ((dts == null) || (dts.isEmpty())) {
        return;
    }
    TimeZone tz = null;
    if (!val.getForceUTC()) {
        BwDateTime dtstart = val.getDtstart();
        if ((dtstart != null) && !dtstart.isUTC()) {
            DtStart ds = dtstart.makeDtStart();
            tz = ds.getTimeZone();
        }
    }
    /* Generate as one date per property - matches up to other vendors better */
    for (BwDateTime dt : dts) {
        DateList dl = null;
        /* Always use the UTC values */
        boolean dateType = false;
        if (dt.getDateType()) {
            dl = new DateList(Value.DATE);
            dl.setUtc(true);
            dateType = true;
            dl.add(new Date(dt.getDtval()));
        } else {
            dl = new DateList(Value.DATE_TIME);
            if (tz == null) {
                dl.setUtc(true);
                DateTime dtm = new DateTime(dt.getDate());
                dtm.setUtc(true);
                dl.add(dtm);
            } else {
                dl.setTimeZone(tz);
                DateTime dtm = new DateTime(dt.getDate());
                dtm.setTimeZone(tz);
                dl.add(dtm);
            }
        }
        DateListProperty dlp;
        if (exdt) {
            dlp = new ExDate(dl);
        } else {
            dlp = new RDate(dl);
        }
        if (tz != null) {
            dlp.setTimeZone(tz);
        }
        if (dateType) {
            dlp.getParameters().add(Value.DATE);
        }
        pl.add(dlp);
    }
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) DtStart(net.fortuna.ical4j.model.property.DtStart) RDate(net.fortuna.ical4j.model.property.RDate) BwDateTime(org.bedework.calfacade.BwDateTime) DateListProperty(net.fortuna.ical4j.model.property.DateListProperty) ExDate(net.fortuna.ical4j.model.property.ExDate) DateList(net.fortuna.ical4j.model.DateList) Date(net.fortuna.ical4j.model.Date) RDate(net.fortuna.ical4j.model.property.RDate) ExDate(net.fortuna.ical4j.model.property.ExDate) DateTime(net.fortuna.ical4j.model.DateTime) BwDateTime(org.bedework.calfacade.BwDateTime)

Example 10 with DateList

use of net.fortuna.ical4j.model.DateList in project openolat by klemens.

the class CalendarUtils method getRecurrenceExcludeRule.

/**
 * Create exclusion rule based on list with dates.
 * @param dates
 * @return string with exclude rule
 */
public static String getRecurrenceExcludeRule(List<Date> dates) {
    if (dates != null && dates.size() > 0) {
        DateList dl = new DateList();
        for (Date date : dates) {
            net.fortuna.ical4j.model.Date dd = CalendarUtils.createDate(date);
            dl.add(dd);
        }
        ExDate exdate = new ExDate(dl);
        return exdate.getValue();
    }
    return null;
}
Also used : ExDate(net.fortuna.ical4j.model.property.ExDate) DateList(net.fortuna.ical4j.model.DateList) Date(java.util.Date) ExDate(net.fortuna.ical4j.model.property.ExDate)

Aggregations

DateList (net.fortuna.ical4j.model.DateList)10 ExDate (net.fortuna.ical4j.model.property.ExDate)7 ParseException (java.text.ParseException)4 Date (java.util.Date)4 Date (net.fortuna.ical4j.model.Date)4 BwDateTime (org.bedework.calfacade.BwDateTime)4 DateTime (net.fortuna.ical4j.model.DateTime)3 RDate (net.fortuna.ical4j.model.property.RDate)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 Dur (net.fortuna.ical4j.model.Dur)2 Recur (net.fortuna.ical4j.model.Recur)2 TreeSet (java.util.TreeSet)1 Parameter (net.fortuna.ical4j.model.Parameter)1 Period (net.fortuna.ical4j.model.Period)1 PeriodList (net.fortuna.ical4j.model.PeriodList)1 PropertyList (net.fortuna.ical4j.model.PropertyList)1 TimeZone (net.fortuna.ical4j.model.TimeZone)1 DateListProperty (net.fortuna.ical4j.model.property.DateListProperty)1 DtStart (net.fortuna.ical4j.model.property.DtStart)1