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));
}
}
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));
}
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;
}
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;
}
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;
}
Aggregations