nKognito
nKognito

Reputation: 6363

Set event's time with iCal4j

I trying to implement simple export function into ics file. Events exported fine, but there is an issue with times - they are missing in exported file but exists in original format. Here is the code:

TimeZone timeZone = TimeZone.getTimeZone(e.getOrder().getTimeZone()); long timeZoneOffset = TimeUnit.MILLISECONDS.toMinutes(timeZone.getOffset(now.getTime()));

startDate = new net.fortuna.ical4j.model.Date(DateUtils.addMinutes(e.getStartDateTime(), (int) timeZoneOffset).getTime());
endDate = new net.fortuna.ical4j.model.Date(DateUtils.addMinutes(e.getEndDateTime(), (int) timeZoneOffset).getTime());
event = new VEvent(startDate, endDate, e.getOrder().getDescription());
event.getProperties().add(TimeZoneRegistryFactory.getInstance().createRegistry().getTimeZone(e.getOrder().getTimeZone()).getVTimeZone().getTimeZoneId());
event.getProperties().add(new UidGenerator("CA").generateUid());
calendar.getComponents().add(event);

What I missed? Thank you in advance!

Upvotes: 0

Views: 2140

Answers (1)

user4137911
user4137911

Reputation: 56

I wasn't able to reproduce you code, as you haven't pasted your code example fully and correctly (maybe you could do so and include the imports? That would make answering your question more easy).

But nevertheless, did you already had a look at the biweekly library (see: http://sourceforge.net/projects/biweekly/)? It looks pretty straightforward to me: easy to understand and you don't need to mess around with the iCal4j Date/TimeZone classes, etc. which seemed pretty cumbersome on my first peek.

Here is some example code giving you a glimpse about it's fairly intuitive usage:

ICalendar icals = new ICalendar();
VEvent event = new VEvent();
event.setDateStart(new Date());
event.setDateEnd(new Date());
event.setDescription("some description");

icals.setProductId("some product ID");
icals.addEvent(event);

WriterChainText text = Biweekly.write(icals);
System.out.println(text.go());

It can be included easily via Maven using:

<dependency>
    <groupId>net.sf.biweekly</groupId>
    <artifactId>biweekly</artifactId>
    <version>0.3.3</version>
</dependency>

Hope that helps?

Upvotes: 2

Related Questions