use of net.fortuna.ical4j.model.Date 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;
}
use of net.fortuna.ical4j.model.Date 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);
}
}
use of net.fortuna.ical4j.model.Date in project bw-calendar-engine by Bedework.
the class VEventUtil method makeZonedDt.
private static Date makeZonedDt(final BwEvent val, final String dtval) throws Throwable {
BwDateTime dtstart = val.getDtstart();
Date dt = new DateTime(dtval);
if (dtstart.getDateType()) {
// RECUR - fix all day recurrences sometime
if (dtval.length() > 8) {
// Try to fix up bad all day recurrence ids. - assume a local timezone
((DateTime) dt).setTimeZone(null);
return new Date(dt.toString().substring(0, 8));
}
return dt;
}
if (val.getForceUTC()) {
return dt;
}
if ((dtstart != null) && !dtstart.isUTC()) {
DtStart ds = dtstart.makeDtStart();
((DateTime) dt).setTimeZone(ds.getTimeZone());
}
return dt;
}
use of net.fortuna.ical4j.model.Date in project zm-mailbox by Zimbra.
the class TestUserServlet method testIcsImportExport.
/**
* Test that can import into a new calendar from ICALENDAR containing an inline ATTACHment.
* Test that it is possible to export calendar entry with an attachment with the attachment
* inlined if icalAttach=inline or ignoring the attachment if icalAttach=none
* @throws Exception
*/
@Test
public void testIcsImportExport() throws Exception {
ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
String calName = NAME_PREFIX + "2ndCalendar";
String calUri = String.format("/%s?fmt=ics", calName);
TestUtil.createFolder(mbox, calName, ZFolder.View.appointment);
net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
calendar.getProperties().add(new ProdId("-//ZimbraTest 1.0//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
java.util.Calendar start = java.util.Calendar.getInstance();
start.set(java.util.Calendar.MONTH, java.util.Calendar.SEPTEMBER);
start.set(java.util.Calendar.DAY_OF_MONTH, 03);
VEvent wwII = new VEvent(new Date(start.getTime()), NAME_PREFIX + " Declarations of war");
wwII.getProperties().getProperty(Property.DTSTART).getParameters().add(Value.DATE);
wwII.getProperties().add(new Uid("3-14159"));
Attach attach = new Attach("Attachment.\nIsn't it short.".getBytes(MimeConstants.P_CHARSET_ASCII));
attach.getParameters().add(new XParameter("X-APPLE-FILENAME", "short.txt"));
attach.getParameters().add(new FmtType(MimeConstants.CT_TEXT_PLAIN));
wwII.getProperties().add(attach);
calendar.getComponents().add(wwII);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
CalendarOutputter outputter = new CalendarOutputter();
outputter.setValidating(false);
outputter.output(calendar, buf);
URI uri = mbox.getRestURI(calUri);
HttpClient client = mbox.getHttpClient(uri);
HttpPost post = new HttpPost(uri.toString());
post.setEntity(new InputStreamEntity(new ByteArrayInputStream(buf.toByteArray()), ContentType.create(MimeConstants.CT_TEXT_CALENDAR)));
ZimbraLog.test.info("testIcsImportExport:ICS to be imported:%s", new String(buf.toByteArray()));
TestCalDav.HttpMethodExecutor.execute(client, post, HttpStatus.SC_OK);
uri = mbox.getRestURI(calUri + "&icalAttach=inline");
HttpGet get = new HttpGet(uri.toString());
TestCalDav.HttpMethodExecutor executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
String respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.info("testIcsImportExport:ICS exported (with icalAttach=inline):%s", respIcal);
int attachNdx = respIcal.indexOf("ATTACH;");
Assert.assertTrue("ATTACH should be present", -1 != attachNdx);
String fromAttach = respIcal.substring(attachNdx);
Assert.assertTrue("BINARY should be present", -1 != fromAttach.indexOf("VALUE=BINARY"));
uri = mbox.getRestURI(calUri + "&icalAttach=none");
get = new HttpGet(uri.toString());
executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.debug("testIcsImportExport:ICS exported (with icalAttach=none):%s", respIcal);
Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
uri = mbox.getRestURI(calUri);
get = new HttpGet(uri.toString());
executor = new TestCalDav.HttpMethodExecutor(client, get, HttpStatus.SC_OK);
respIcal = new String(executor.responseBodyBytes, MimeConstants.P_CHARSET_UTF8);
ZimbraLog.test.debug("testIcsImportExport:ICS exported (default - same as icalAttach=none):%s", respIcal);
Assert.assertTrue("ATTACH should be present", -1 == respIcal.indexOf("ATTACH;"));
}
Aggregations