Search in sources :

Example 1 with DtEnd

use of net.fortuna.ical4j.model.property.DtEnd in project camel by apache.

the class ICalDataFormatTest method createTestCalendar.

/**
     * Creates test calendar instance.
     * 
     * @return ICal calendar object.
     */
protected Calendar createTestCalendar() throws ParseException {
    // Create a TimeZone
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone("America/New_York");
    VTimeZone tz = timezone.getVTimeZone();
    // Start Date is on: April 1, 2013, 9:00 am
    java.util.Calendar startDate = new GregorianCalendar();
    startDate.setTimeZone(timezone);
    startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
    startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
    startDate.set(java.util.Calendar.YEAR, 2013);
    startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
    startDate.set(java.util.Calendar.MINUTE, 0);
    startDate.set(java.util.Calendar.SECOND, 0);
    // End Date is on: April 1, 2013, 13:00
    java.util.Calendar endDate = new GregorianCalendar();
    endDate.setTimeZone(timezone);
    endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
    endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
    endDate.set(java.util.Calendar.YEAR, 2013);
    endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
    endDate.set(java.util.Calendar.MINUTE, 0);
    endDate.set(java.util.Calendar.SECOND, 0);
    // Create the event
    PropertyList propertyList = new PropertyList();
    propertyList.add(new DtStamp("20130324T180000Z"));
    propertyList.add(new DtStart(new DateTime(startDate.getTime())));
    propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
    propertyList.add(new Summary("Progress Meeting"));
    VEvent meeting = new VEvent(propertyList);
    // add timezone info..
    meeting.getProperties().add(tz.getTimeZoneId());
    // generate unique identifier..
    meeting.getProperties().add(new Uid("00000000"));
    // add attendees..
    Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn("Developer 1"));
    meeting.getProperties().add(dev1);
    Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
    dev2.getParameters().add(Role.OPT_PARTICIPANT);
    dev2.getParameters().add(new Cn("Developer 2"));
    meeting.getProperties().add(dev2);
    // Create a calendar
    net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
    icsCalendar.getProperties().add(Version.VERSION_2_0);
    icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
    icsCalendar.getProperties().add(CalScale.GREGORIAN);
    // Add the event and print
    icsCalendar.getComponents().add(meeting);
    return icsCalendar;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) GregorianCalendar(java.util.GregorianCalendar) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) GregorianCalendar(java.util.GregorianCalendar) Cn(net.fortuna.ical4j.model.parameter.Cn) ProdId(net.fortuna.ical4j.model.property.ProdId) Calendar(net.fortuna.ical4j.model.Calendar) DateTime(net.fortuna.ical4j.model.DateTime) Attendee(net.fortuna.ical4j.model.property.Attendee) Uid(net.fortuna.ical4j.model.property.Uid) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) TimeZone(net.fortuna.ical4j.model.TimeZone) DtStamp(net.fortuna.ical4j.model.property.DtStamp) PropertyList(net.fortuna.ical4j.model.PropertyList) DtStart(net.fortuna.ical4j.model.property.DtStart) Summary(net.fortuna.ical4j.model.property.Summary) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 2 with DtEnd

use of net.fortuna.ical4j.model.property.DtEnd in project android by nextcloud.

the class SaveCalendar method convertFromDb.

private VEvent convertFromDb(Cursor cur, Calendar cal, DtStamp timestamp) {
    Log_OC.d(TAG, "cursor: " + DatabaseUtils.dumpCurrentRowToString(cur));
    if (hasStringValue(cur, Events.ORIGINAL_ID)) {
        // FIXME: Support these edited instances
        Log_OC.w(TAG, "Ignoring edited instance of a recurring event");
        return null;
    }
    PropertyList l = new PropertyList();
    l.add(timestamp);
    copyProperty(l, Property.UID, cur, Events.UID_2445);
    String summary = copyProperty(l, Property.SUMMARY, cur, Events.TITLE);
    String description = copyProperty(l, Property.DESCRIPTION, cur, Events.DESCRIPTION);
    String organizer = getString(cur, Events.ORGANIZER);
    if (!TextUtils.isEmpty(organizer)) {
        // incorrectly left it in the organizer column.
        if (!organizer.startsWith("mailto:")) {
            organizer = "mailto:" + organizer;
        }
        try {
            l.add(new Organizer(organizer));
        } catch (URISyntaxException ignored) {
            if (!mFailedOrganisers.contains(organizer)) {
                Log_OC.e(TAG, "Failed to create mailTo for organizer " + organizer);
                mFailedOrganisers.add(organizer);
            }
        }
    }
    copyProperty(l, Property.LOCATION, cur, Events.EVENT_LOCATION);
    copyEnumProperty(l, Property.STATUS, cur, Events.STATUS, STATUS_ENUM);
    boolean allDay = TextUtils.equals(getString(cur, Events.ALL_DAY), "1");
    boolean isTransparent;
    DtEnd dtEnd = null;
    if (allDay) {
        // All day event
        isTransparent = true;
        Date start = getDateTime(cur, Events.DTSTART, null, null);
        Date end = getDateTime(cur, Events.DTEND, null, null);
        l.add(new DtStart(new Date(start)));
        if (end != null) {
            dtEnd = new DtEnd(new Date(end));
        } else {
            dtEnd = new DtEnd(utcDateFromMs(start.getTime() + DateUtils.DAY_IN_MILLIS));
        }
        l.add(dtEnd);
    } else {
        // Regular or zero-time event. Start date must be a date-time
        Date startDate = getDateTime(cur, Events.DTSTART, Events.EVENT_TIMEZONE, cal);
        l.add(new DtStart(startDate));
        // Use duration if we have one, otherwise end date
        if (hasStringValue(cur, Events.DURATION)) {
            isTransparent = getString(cur, Events.DURATION).equals("PT0S");
            if (!isTransparent) {
                copyProperty(l, Property.DURATION, cur, Events.DURATION);
            }
        } else {
            String endTz = Events.EVENT_END_TIMEZONE;
            if (endTz == null) {
                endTz = Events.EVENT_TIMEZONE;
            }
            Date end = getDateTime(cur, Events.DTEND, endTz, cal);
            dtEnd = new DtEnd(end);
            isTransparent = startDate.getTime() == end.getTime();
            if (!isTransparent) {
                l.add(dtEnd);
            }
        }
    }
    copyEnumProperty(l, Property.CLASS, cur, Events.ACCESS_LEVEL, CLASS_ENUM);
    int availability = getInt(cur, Events.AVAILABILITY);
    if (availability > Events.AVAILABILITY_TENTATIVE) {
        // Unknown/Invalid
        availability = -1;
    }
    if (isTransparent) {
        // not free, then mark it opaque.
        if (availability >= 0 && availability != Events.AVAILABILITY_FREE) {
            l.add(Transp.OPAQUE);
        }
    } else if (availability > Events.AVAILABILITY_BUSY) {
        // This event is ordinarily busy but differs, so output a FREEBUSY
        // period covering the time of the event
        FreeBusy fb = new FreeBusy();
        fb.getParameters().add(new FbType(AVAIL_ENUM.get(availability)));
        DateTime start = new DateTime(((DtStart) l.getProperty(Property.DTSTART)).getDate());
        if (dtEnd != null) {
            fb.getPeriods().add(new Period(start, new DateTime(dtEnd.getDate())));
        } else {
            Duration d = (Duration) l.getProperty(Property.DURATION);
            fb.getPeriods().add(new Period(start, d.getDuration()));
        }
        l.add(fb);
    }
    copyProperty(l, Property.RRULE, cur, Events.RRULE);
    copyProperty(l, Property.RDATE, cur, Events.RDATE);
    copyProperty(l, Property.EXRULE, cur, Events.EXRULE);
    copyProperty(l, Property.EXDATE, cur, Events.EXDATE);
    if (TextUtils.isEmpty(getString(cur, Events.CUSTOM_APP_PACKAGE))) {
        // Only copy URL if there is no app i.e. we probably imported it.
        copyProperty(l, Property.URL, cur, Events.CUSTOM_APP_URI);
    }
    VEvent e = new VEvent(l);
    if (getInt(cur, Events.HAS_ALARM) == 1) {
        // Add alarms
        String s = summary == null ? (description == null ? "" : description) : summary;
        Description desc = new Description(s);
        ContentResolver resolver = activity.getContentResolver();
        long eventId = getLong(cur, Events._ID);
        Cursor alarmCur;
        alarmCur = Reminders.query(resolver, eventId, mAllCols ? null : REMINDER_COLS);
        while (alarmCur.moveToNext()) {
            int mins = getInt(alarmCur, Reminders.MINUTES);
            if (mins == -1) {
                // FIXME: Get the real default
                mins = 60;
            }
            // FIXME: We should support other types if possible
            int method = getInt(alarmCur, Reminders.METHOD);
            if (method == Reminders.METHOD_DEFAULT || method == Reminders.METHOD_ALERT) {
                VAlarm alarm = new VAlarm(new Dur(0, 0, -mins, 0));
                alarm.getProperties().add(Action.DISPLAY);
                alarm.getProperties().add(desc);
                e.getAlarms().add(alarm);
            }
        }
        alarmCur.close();
    }
    return e;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Dur(net.fortuna.ical4j.model.Dur) Description(net.fortuna.ical4j.model.property.Description) Organizer(net.fortuna.ical4j.model.property.Organizer) FreeBusy(net.fortuna.ical4j.model.property.FreeBusy) Period(net.fortuna.ical4j.model.Period) Duration(net.fortuna.ical4j.model.property.Duration) URISyntaxException(java.net.URISyntaxException) Cursor(android.database.Cursor) Date(net.fortuna.ical4j.model.Date) SuppressLint(android.annotation.SuppressLint) DateTime(net.fortuna.ical4j.model.DateTime) ContentResolver(android.content.ContentResolver) PropertyList(net.fortuna.ical4j.model.PropertyList) DtStart(net.fortuna.ical4j.model.property.DtStart) FbType(net.fortuna.ical4j.model.parameter.FbType) VAlarm(net.fortuna.ical4j.model.component.VAlarm) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 3 with DtEnd

use of net.fortuna.ical4j.model.property.DtEnd in project wildfly-camel by wildfly-extras.

the class ICalFormatTest method createTestCalendar.

private Calendar createTestCalendar() throws ParseException {
    // Create a TimeZone
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone("America/New_York");
    VTimeZone tz = timezone.getVTimeZone();
    // Start Date is on: April 1, 2013, 9:00 am
    java.util.Calendar startDate = new GregorianCalendar();
    startDate.setTimeZone(timezone);
    startDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
    startDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
    startDate.set(java.util.Calendar.YEAR, 2013);
    startDate.set(java.util.Calendar.HOUR_OF_DAY, 17);
    startDate.set(java.util.Calendar.MINUTE, 0);
    startDate.set(java.util.Calendar.SECOND, 0);
    // End Date is on: April 1, 2013, 13:00
    java.util.Calendar endDate = new GregorianCalendar();
    endDate.setTimeZone(timezone);
    endDate.set(java.util.Calendar.MONTH, java.util.Calendar.APRIL);
    endDate.set(java.util.Calendar.DAY_OF_MONTH, 1);
    endDate.set(java.util.Calendar.YEAR, 2013);
    endDate.set(java.util.Calendar.HOUR_OF_DAY, 21);
    endDate.set(java.util.Calendar.MINUTE, 0);
    endDate.set(java.util.Calendar.SECOND, 0);
    // Create the event
    PropertyList propertyList = new PropertyList();
    propertyList.add(new DtStamp("20130324T180000Z"));
    propertyList.add(new DtStart(new DateTime(startDate.getTime())));
    propertyList.add(new DtEnd(new DateTime(endDate.getTime())));
    propertyList.add(new Summary("Progress Meeting"));
    VEvent meeting = new VEvent(propertyList);
    // add timezone info..
    meeting.getProperties().add(tz.getTimeZoneId());
    // generate unique identifier..
    meeting.getProperties().add(new Uid("00000000"));
    // add attendees..
    Attendee dev1 = new Attendee(URI.create("mailto:dev1@mycompany.com"));
    dev1.getParameters().add(Role.REQ_PARTICIPANT);
    dev1.getParameters().add(new Cn("Developer 1"));
    meeting.getProperties().add(dev1);
    Attendee dev2 = new Attendee(URI.create("mailto:dev2@mycompany.com"));
    dev2.getParameters().add(Role.OPT_PARTICIPANT);
    dev2.getParameters().add(new Cn("Developer 2"));
    meeting.getProperties().add(dev2);
    // Create a calendar
    net.fortuna.ical4j.model.Calendar icsCalendar = new net.fortuna.ical4j.model.Calendar();
    icsCalendar.getProperties().add(Version.VERSION_2_0);
    icsCalendar.getProperties().add(new ProdId("-//Events Calendar//iCal4j 1.0//EN"));
    icsCalendar.getProperties().add(CalScale.GREGORIAN);
    // Add the event and print
    icsCalendar.getComponents().add(meeting);
    return icsCalendar;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) GregorianCalendar(java.util.GregorianCalendar) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) GregorianCalendar(java.util.GregorianCalendar) Cn(net.fortuna.ical4j.model.parameter.Cn) ProdId(net.fortuna.ical4j.model.property.ProdId) Calendar(net.fortuna.ical4j.model.Calendar) DateTime(net.fortuna.ical4j.model.DateTime) Attendee(net.fortuna.ical4j.model.property.Attendee) Uid(net.fortuna.ical4j.model.property.Uid) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) TimeZone(net.fortuna.ical4j.model.TimeZone) DtStamp(net.fortuna.ical4j.model.property.DtStamp) PropertyList(net.fortuna.ical4j.model.PropertyList) DtStart(net.fortuna.ical4j.model.property.DtStart) Summary(net.fortuna.ical4j.model.property.Summary) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 4 with DtEnd

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

the class BwDateTime method addDuration.

private BwDateTime addDuration(final Dur val) throws CalFacadeException {
    DtEnd dtEnd;
    java.util.Date endDt = val.getTime(makeDate());
    DtStart dtStart = makeDtStart(Timezones.getTzRegistry());
    if (getDateType()) {
        dtEnd = new DtEnd(new Date(endDt));
        addIcalParameter(dtEnd, Value.DATE);
    } else {
        DateTime d = new DateTime(endDt);
        Parameter tzid = getIcalParameter(dtStart, "TZID");
        if (tzid != null) {
            DateTime sd = (DateTime) dtStart.getDate();
            d.setTimeZone(sd.getTimeZone());
        }
        // dtEnd = new DtEnd(d, dtStart.isUtc());
        dtEnd = new DtEnd(d);
        if (tzid != null) {
            addIcalParameter(dtEnd, tzid);
        } else if (dtStart.isUtc()) {
            dtEnd.setUtc(true);
        }
    }
    return makeBwDateTime(dtEnd);
}
Also used : DtStart(net.fortuna.ical4j.model.property.DtStart) Parameter(net.fortuna.ical4j.model.Parameter) Date(net.fortuna.ical4j.model.Date) DateTime(net.fortuna.ical4j.model.DateTime) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Example 5 with DtEnd

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

the class BwDateTime method makeDtEnd.

/**
 * Make a DtEnd from this object
 *
 * @param tzreg
 * @return DtEnd
 * @throws CalFacadeException
 */
public DtEnd makeDtEnd(final TimeZoneRegistry tzreg) throws CalFacadeException {
    try {
        DtEnd dt = new DtEnd();
        initDateProp(dt, tzreg);
        return dt;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Aggregations

DtEnd (net.fortuna.ical4j.model.property.DtEnd)15 DtStart (net.fortuna.ical4j.model.property.DtStart)11 Date (net.fortuna.ical4j.model.Date)8 DateTime (net.fortuna.ical4j.model.DateTime)7 Dur (net.fortuna.ical4j.model.Dur)7 PropertyList (net.fortuna.ical4j.model.PropertyList)7 VEvent (net.fortuna.ical4j.model.component.VEvent)7 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)7 BwDateTime (org.bedework.calfacade.BwDateTime)6 Duration (net.fortuna.ical4j.model.property.Duration)5 BwEvent (org.bedework.calfacade.BwEvent)5 Calendar (net.fortuna.ical4j.model.Calendar)4 Period (net.fortuna.ical4j.model.Period)4 Parameter (net.fortuna.ical4j.model.Parameter)3 PeriodList (net.fortuna.ical4j.model.PeriodList)3 TimeZone (net.fortuna.ical4j.model.TimeZone)3 TimeZoneRegistry (net.fortuna.ical4j.model.TimeZoneRegistry)3 Attendee (net.fortuna.ical4j.model.property.Attendee)3 DtStamp (net.fortuna.ical4j.model.property.DtStamp)3 Summary (net.fortuna.ical4j.model.property.Summary)3