Search in sources :

Example 41 with DateTime

use of net.fortuna.ical4j.model.DateTime in project opencast by opencast.

the class IndexServiceImplTest method calculateDSTChange.

@Test
public void calculateDSTChange() throws ParseException {
    Calendar start;
    Calendar end;
    long durationMillis;
    String days;
    List<Period> periods;
    // CET
    TimeZone.setDefault(cet);
    start = Calendar.getInstance(cet);
    start.set(2016, 2, 24, 0, 5);
    end = Calendar.getInstance(cet);
    end.set(2016, 2, 29, start.get(Calendar.HOUR_OF_DAY), 10);
    durationMillis = (end.get(Calendar.MINUTE) - start.get(Calendar.MINUTE)) * 60 * 1000;
    days = "MO,TH,FR,SA,SU";
    periods = generatePeriods(cet, start, end, days, durationMillis);
    assertEquals(5, periods.size());
    TimeZone.setDefault(cet);
    for (Period d : periods) {
        DateTime dEnd = d.getEnd();
        Date date = new Date(dEnd.getTime());
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);
        assertEquals(0, instance.get(Calendar.HOUR_OF_DAY));
    }
}
Also used : Calendar(java.util.Calendar) Period(net.fortuna.ical4j.model.Period) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) Test(org.junit.Test)

Example 42 with DateTime

use of net.fortuna.ical4j.model.DateTime in project ofbiz-framework by apache.

the class ICalRecurConverter method visit.

@Override
public void visit(TemporalExpressions.DateRange expr) {
    if (this.state.isExcluded) {
        throw new IllegalStateException("iCalendar does not support excluded date ranges");
    }
    org.apache.ofbiz.base.util.DateRange range = expr.getDateRange();
    PeriodList periodList = new PeriodList();
    periodList.add(new Period(new DateTime(range.start()), new DateTime(range.end())));
    this.incDateList.add(new RDate(periodList));
}
Also used : RDate(net.fortuna.ical4j.model.property.RDate) PeriodList(net.fortuna.ical4j.model.PeriodList) Period(net.fortuna.ical4j.model.Period) DateTime(net.fortuna.ical4j.model.DateTime)

Example 43 with DateTime

use of net.fortuna.ical4j.model.DateTime in project opencast by opencast.

the class CalendarGenerator method addEvent.

/**
 * Adds an SchedulerEvent as a new entry to this iCalendar
 *
 * @param mp
 *          {@link MediaPackage} of event
 * @param agentId
 *          the agent identifier
 * @param start
 *          the start date
 * @param end
 *          the end date
 * @param captureAgentMetadata
 *          properties for capture agent metadata
 *
 * @return true if the event could be added.
 */
public boolean addEvent(MediaPackage mp, DublinCoreCatalog catalog, String agentId, Date start, Date end, Date lastModified, String captureAgentMetadata) {
    String eventId = mp.getIdentifier().compact();
    logger.debug("Creating iCaleandar VEvent from scheduled event '{}'", eventId);
    DateTime startDate = new DateTime(start);
    DateTime endDate = new DateTime(end);
    Date marginEndDate = new org.joda.time.DateTime(endDate.getTime()).plusHours(1).toDate();
    if (marginEndDate.before(new Date())) {
        logger.debug("Event has already passed more than an hour, skipping!");
        return false;
    }
    startDate.setUtc(true);
    endDate.setUtc(true);
    String seriesID = null;
    VEvent event = new VEvent(startDate, endDate, catalog.getFirst(DublinCore.PROPERTY_TITLE));
    try {
        ParameterList pl = new ParameterList();
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            pl.add(new Cn(catalog.getFirst(DublinCore.PROPERTY_CREATOR)));
        }
        event.getProperties().add(new Uid(eventId));
        DateTime lastModifiedDate = new DateTime(lastModified);
        lastModifiedDate.setUtc(true);
        event.getProperties().add(new LastModified(lastModifiedDate));
        // TODO Organizer should be URI (email-address?) created fake address
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_CREATOR))) {
            URI organizer = new URI("mailto", catalog.getFirst(DublinCore.PROPERTY_CREATOR) + "@opencast.tld", null);
            event.getProperties().add(new Organizer(pl, organizer));
        }
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION))) {
            event.getProperties().add(new Description(catalog.getFirst(DublinCore.PROPERTY_DESCRIPTION)));
        }
        event.getProperties().add(new Location(agentId));
        if (StringUtils.isNotEmpty(catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF))) {
            seriesID = catalog.getFirst(DublinCore.PROPERTY_IS_PART_OF);
            event.getProperties().add(new RelatedTo(seriesID));
        }
        ParameterList dcParameters = new ParameterList();
        dcParameters.add(new FmtType("application/xml"));
        dcParameters.add(Value.BINARY);
        dcParameters.add(Encoding.BASE64);
        dcParameters.add(new XParameter("X-APPLE-FILENAME", "episode.xml"));
        Attach metadataAttachment = new Attach(dcParameters, catalog.toXmlString().getBytes("UTF-8"));
        event.getProperties().add(metadataAttachment);
        String seriesDC = getSeriesDublinCoreAsString(seriesID);
        if (seriesDC != null) {
            logger.debug("Attaching series {} information to event {}", seriesID, eventId);
            ParameterList sDcParameters = new ParameterList();
            sDcParameters.add(new FmtType("application/xml"));
            sDcParameters.add(Value.BINARY);
            sDcParameters.add(Encoding.BASE64);
            sDcParameters.add(new XParameter("X-APPLE-FILENAME", "series.xml"));
            Attach seriesAttachment = new Attach(sDcParameters, seriesDC.getBytes("UTF-8"));
            event.getProperties().add(seriesAttachment);
        } else {
            logger.debug("No series provided for event {}.", eventId);
        }
        ParameterList caParameters = new ParameterList();
        caParameters.add(new FmtType("application/text"));
        caParameters.add(Value.BINARY);
        caParameters.add(Encoding.BASE64);
        caParameters.add(new XParameter("X-APPLE-FILENAME", "org.opencastproject.capture.agent.properties"));
        Attach agentsAttachment = new Attach(caParameters, captureAgentMetadata.getBytes("UTF-8"));
        event.getProperties().add(agentsAttachment);
    } catch (Exception e) {
        logger.error("Unable to add event '{}' to recording calendar: {}", eventId, ExceptionUtils.getStackTrace(e));
        return false;
    }
    cal.getComponents().add(event);
    logger.debug("new VEvent = {} ", event.toString());
    return true;
}
Also used : VEvent(net.fortuna.ical4j.model.component.VEvent) Description(net.fortuna.ical4j.model.property.Description) Organizer(net.fortuna.ical4j.model.property.Organizer) Attach(net.fortuna.ical4j.model.property.Attach) Cn(net.fortuna.ical4j.model.parameter.Cn) URI(java.net.URI) DateTime(net.fortuna.ical4j.model.DateTime) Date(java.util.Date) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) LastModified(net.fortuna.ical4j.model.property.LastModified) Uid(net.fortuna.ical4j.model.property.Uid) FmtType(net.fortuna.ical4j.model.parameter.FmtType) ParameterList(net.fortuna.ical4j.model.ParameterList) RelatedTo(net.fortuna.ical4j.model.property.RelatedTo) XParameter(net.fortuna.ical4j.model.parameter.XParameter) Location(net.fortuna.ical4j.model.property.Location)

Example 44 with DateTime

use of net.fortuna.ical4j.model.DateTime in project traccar by tananaev.

the class Calendar method checkMoment.

public boolean checkMoment(Date date) {
    if (calendar != null) {
        Period period = new Period(new DateTime(date), Duration.ZERO);
        Filter<CalendarComponent> filter = new Filter<>(new PeriodRule<>(period));
        Collection<CalendarComponent> events = filter.filter(calendar.getComponents(CalendarComponent.VEVENT));
        return events != null && !events.isEmpty();
    }
    return false;
}
Also used : CalendarComponent(net.fortuna.ical4j.model.component.CalendarComponent) Filter(net.fortuna.ical4j.filter.Filter) Period(net.fortuna.ical4j.model.Period) DateTime(net.fortuna.ical4j.model.DateTime)

Example 45 with DateTime

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

the class SchedulingViewOfTnef method getStartTime.

/**
 * @return the time in UTC that the meeting object was sent or null
 * @throws IOException
 */
public DateTime getStartTime() throws IOException {
    // Specifies the start date and time of the event in UTC
    DateTime timeVal = null;
    if (this.getIcalType() == ICALENDAR_TYPE.VTODO) {
        /* PidLidTaskStartDate Unset or has value 0x5AE980E0
             *        --> task does not have a start date
             */
        Long taskStartDateNum = MapiPropertyId.PidLidTaskStartDate.get100nsPeriodsSince1601(this);
        if (taskStartDateNum == null) {
            return null;
        }
        if (taskStartDateNum == 0x5AE980E0) {
            sLog.debug("PidLidTaskStartDate as num 0x%s [means NO start date]", Long.toHexString(taskStartDateNum));
            return null;
        }
        timeVal = MapiPropertyId.PidLidTaskStartDate.getDateTimeAsUTC(this);
    } else {
        // PidLidAppointmentStartWhole - UTC start date and time for the event.
        timeVal = MapiPropertyId.PidLidAppointmentStartWhole.getDateTimeAsUTC(this);
    }
    if (timeVal == null) {
        timeVal = MapiPropertyId.PidTagStartDate.getDateTimeAsUTC(this);
    }
    return timeVal;
}
Also used : DateTime(net.fortuna.ical4j.model.DateTime)

Aggregations

DateTime (net.fortuna.ical4j.model.DateTime)70 Period (net.fortuna.ical4j.model.Period)20 VEvent (net.fortuna.ical4j.model.component.VEvent)18 BwDateTime (org.bedework.calfacade.BwDateTime)15 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)15 Date (java.util.Date)13 TimeZone (net.fortuna.ical4j.model.TimeZone)13 ParseException (java.text.ParseException)12 DtStart (net.fortuna.ical4j.model.property.DtStart)11 Date (net.fortuna.ical4j.model.Date)10 Dur (net.fortuna.ical4j.model.Dur)10 PeriodList (net.fortuna.ical4j.model.PeriodList)10 PropertyList (net.fortuna.ical4j.model.PropertyList)9 DtStamp (net.fortuna.ical4j.model.property.DtStamp)9 LastModified (net.fortuna.ical4j.model.property.LastModified)9 Uid (net.fortuna.ical4j.model.property.Uid)9 Calendar (net.fortuna.ical4j.model.Calendar)8 Recur (net.fortuna.ical4j.model.Recur)8 ExDate (net.fortuna.ical4j.model.property.ExDate)8 GregorianCalendar (java.util.GregorianCalendar)7