Search in sources :

Example 1 with TimeZone

use of net.fortuna.ical4j.model.TimeZone 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 TimeZone

use of net.fortuna.ical4j.model.TimeZone in project zm-mailbox by Zimbra.

the class TimeZoneDefinition method getTimeZone.

/**
     *
     * @return the appropriate iCal4j TimeZone for this TimeZoneDefinition
     */
public TimeZone getTimeZone() {
    if (theZone != null) {
        return theZone;
    }
    if (effectiveRule == null) {
        theZone = new TimeZone(0, TimeZones.UTC_ID);
        return theZone;
    }
    if (!effectiveRule.hasDaylightSaving()) {
        theZone = new TimeZone(effectiveRule.getStandardUtcOffsetMillis(), getTimezoneName());
        return theZone;
    }
    UtcOffset stdOffset = effectiveRule.getStandardUtcOffset();
    UtcOffset dlOffset = effectiveRule.getDaylightUtcOffset();
    PropertyList vtzProps = new PropertyList();
    TzId myTzid = new TzId(getTimezoneName());
    vtzProps.add(myTzid);
    VTimeZone vtz = new VTimeZone(vtzProps);
    Standard stdComp = new Standard();
    stdComp.getProperties().add(effectiveRule.getStandardDtStart());
    stdComp.getProperties().add(effectiveRule.icalStandardRRule());
    TzOffsetFrom offsetFrom = new TzOffsetFrom(dlOffset);
    TzOffsetTo offsetTo = new TzOffsetTo(stdOffset);
    stdComp.getProperties().add(offsetFrom);
    stdComp.getProperties().add(offsetTo);
    Daylight dayComp = new Daylight();
    dayComp.getProperties().add(effectiveRule.getDaylightDtStart());
    dayComp.getProperties().add(effectiveRule.icalDaylightRRule());
    offsetFrom = new TzOffsetFrom(stdOffset);
    offsetTo = new TzOffsetTo(dlOffset);
    dayComp.getProperties().add(offsetFrom);
    dayComp.getProperties().add(offsetTo);
    vtz.getObservances().add(stdComp);
    vtz.getObservances().add(dayComp);
    try {
        vtz.validate(true);
        theZone = new TimeZone(vtz);
    } catch (ValidationException e) {
        if (sLog.isDebugEnabled()) {
            sLog.debug("Problem with property %s - will default to UTC" + this.mpi.toString(), e);
        }
        theZone = new TimeZone(0, TimeZones.UTC_ID);
    }
    theZone = new TimeZone(vtz);
    return theZone;
}
Also used : UtcOffset(net.fortuna.ical4j.model.UtcOffset) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) TimeZone(net.fortuna.ical4j.model.TimeZone) PropertyList(net.fortuna.ical4j.model.PropertyList) Daylight(net.fortuna.ical4j.model.component.Daylight) ValidationException(net.fortuna.ical4j.model.ValidationException) TzOffsetFrom(net.fortuna.ical4j.model.property.TzOffsetFrom) TzOffsetTo(net.fortuna.ical4j.model.property.TzOffsetTo) VTimeZone(net.fortuna.ical4j.model.component.VTimeZone) TzId(net.fortuna.ical4j.model.property.TzId) Standard(net.fortuna.ical4j.model.component.Standard)

Example 3 with TimeZone

use of net.fortuna.ical4j.model.TimeZone in project zm-mailbox by Zimbra.

the class IcalUtil method addPropertyFromUtcTimeAndZone.

/**
     * For use when the utcTime is based on a MAPI property whose value is UTC based rather than
     * localtime based.
     * @param icalOutput
     * @param propName
     * @param utcTime
     * @param tzd
     * @param useDateOnly
     * @throws ParserException
     * @throws URISyntaxException
     * @throws ParseException
     * @throws IOException
     */
public static void addPropertyFromUtcTimeAndZone(ContentHandler icalOutput, String propName, DateTime utcTime, TimeZoneDefinition tzd, boolean useDateOnly) throws ParserException, URISyntaxException, ParseException, IOException {
    if (utcTime == null) {
        return;
    }
    boolean useUtc = true;
    java.util.TimeZone javaTZ = null;
    DateTime localTime = utcTime;
    if (tzd != null) {
        TimeZone tz = tzd.getTimeZone();
        javaTZ = tz;
        if (!tz.getID().equals(TimeZones.UTC_ID)) {
            useUtc = false;
            Calendar actualCalendar = new GregorianCalendar(tz);
            actualCalendar.setTimeInMillis(utcTime.getTime());
            localTime = new DateTime(actualCalendar.getTime());
            localTime.setTimeZone(tz);
        }
    } else {
        javaTZ = TimeZone.getTimeZone(TimeZones.UTC_ID);
    }
    icalOutput.startProperty(propName);
    icalOutput.propertyValue(iCalDateTimeValue(localTime, javaTZ, useDateOnly));
    if (!useUtc) {
        icalOutput.parameter(Parameter.TZID, javaTZ.getID());
    }
    if (useDateOnly) {
        icalOutput.parameter(Parameter.VALUE, Value.DATE.getValue());
    }
    icalOutput.endProperty(propName);
}
Also used : TimeZone(net.fortuna.ical4j.model.TimeZone) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) DateTime(net.fortuna.ical4j.model.DateTime)

Example 4 with TimeZone

use of net.fortuna.ical4j.model.TimeZone in project openhab1-addons by openhab.

the class Util method createCalendar.

public static Calendar createCalendar(CalDavEvent calDavEvent, DateTimeZone timeZone) {
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance().createRegistry();
    TimeZone timezone = registry.getTimeZone(timeZone.getID());
    Calendar calendar = new Calendar();
    calendar.getProperties().add(Version.VERSION_2_0);
    calendar.getProperties().add(new ProdId("openHAB"));
    VEvent vEvent = new VEvent();
    vEvent.getProperties().add(new Summary(calDavEvent.getName()));
    vEvent.getProperties().add(new Description(calDavEvent.getContent()));
    final DtStart dtStart = new DtStart(new net.fortuna.ical4j.model.DateTime(calDavEvent.getStart().toDate()));
    dtStart.setTimeZone(timezone);
    vEvent.getProperties().add(dtStart);
    final DtEnd dtEnd = new DtEnd(new net.fortuna.ical4j.model.DateTime(calDavEvent.getEnd().toDate()));
    dtEnd.setTimeZone(timezone);
    vEvent.getProperties().add(dtEnd);
    vEvent.getProperties().add(new Uid(calDavEvent.getId()));
    vEvent.getProperties().add(Clazz.PUBLIC);
    vEvent.getProperties().add(new LastModified(new net.fortuna.ical4j.model.DateTime(calDavEvent.getLastChanged().toDate())));
    calendar.getComponents().add(vEvent);
    return calendar;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) Calendar(net.fortuna.ical4j.model.Calendar) TimeZoneRegistry(net.fortuna.ical4j.model.TimeZoneRegistry) ProdId(net.fortuna.ical4j.model.property.ProdId) LastModified(net.fortuna.ical4j.model.property.LastModified) Uid(net.fortuna.ical4j.model.property.Uid) DateTimeZone(org.joda.time.DateTimeZone) TimeZone(net.fortuna.ical4j.model.TimeZone) DtStart(net.fortuna.ical4j.model.property.DtStart) Summary(net.fortuna.ical4j.model.property.Summary) DtEnd(net.fortuna.ical4j.model.property.DtEnd)

Aggregations

TimeZone (net.fortuna.ical4j.model.TimeZone)4 GregorianCalendar (java.util.GregorianCalendar)2 Calendar (net.fortuna.ical4j.model.Calendar)2 DateTime (net.fortuna.ical4j.model.DateTime)2 PropertyList (net.fortuna.ical4j.model.PropertyList)2 TimeZoneRegistry (net.fortuna.ical4j.model.TimeZoneRegistry)2 VEvent (net.fortuna.ical4j.model.component.VEvent)2 VTimeZone (net.fortuna.ical4j.model.component.VTimeZone)2 DtEnd (net.fortuna.ical4j.model.property.DtEnd)2 DtStart (net.fortuna.ical4j.model.property.DtStart)2 ProdId (net.fortuna.ical4j.model.property.ProdId)2 Summary (net.fortuna.ical4j.model.property.Summary)2 Uid (net.fortuna.ical4j.model.property.Uid)2 Calendar (java.util.Calendar)1 UtcOffset (net.fortuna.ical4j.model.UtcOffset)1 ValidationException (net.fortuna.ical4j.model.ValidationException)1 Daylight (net.fortuna.ical4j.model.component.Daylight)1 Standard (net.fortuna.ical4j.model.component.Standard)1 Cn (net.fortuna.ical4j.model.parameter.Cn)1 Attendee (net.fortuna.ical4j.model.property.Attendee)1