Question

I making a scheduling application and I am using iCalendar format. I am aware that I can use this code to get the free time slots from current calendar:

DateTime start = new DateTime();
DateTime end = new DateTime(start.getTime() + 1000 * 60 * 60 * 24 * 7);
VFreeBusy request = new VFreeBusy(start, end, new Dur(0, 2, 0, 0));
VFreeBusy response = new VFreeBusy(request, myCalendar.getComponents());

And I get the following output from using this code on a couple of events in the calendar.

DTSTAMP:20140323T204423Z
DTSTART:20020202T040023Z
DTEND:20020203T040023Z
DURATION:PT45M
FREEBUSY;FBTYPE=FREE:20020202T040023Z/PT2H,20020202T070023Z/PT4H,20020202T120023Z/PT16H
END:VFREEBUSY

What I don't know is how to use that VFreeBusy object with those free time slots and actually get them out, so I can compare them and use them as dates and times.

I used response.getProperties().getProperty(Property.FREEBUSY) to get the part that I need, but I don't know how to parse all that String. If you have any other ways for me to get those time slots please advise.

Was it helpful?

Solution

Assuming that you are using ical4j. Once you get the property, you can cast it to a FreeBusy property which has a getPeriods() method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top