0

I am developing an application which reads all the events from the calendar.ics file and then display all the events. My code works fine with individual events and i am able to extract all the events from the file because it contains all the events. But when i create recurring events then i can't get all the events except for the first one, because calendar.ics file contains "RRULE" instead of all the events. I have tried "rfc2445.jar" but it didn't work or maybe i don't know exactly how to use it... Is there any library/code/method/function anything which could help me to parse and display all the events?

 CalendarBuilder builder = new CalendarBuilder();
 Calendar calendar = null;
 calendar = builder.build(file);
 Log.d("RRULE 1: ", component.getProperty("RRULE").getName());
 Log.d("RRULE 2: ", component.getProperty("RRULE").getValue());
 Log.d("RRULE 3: DTSTART: ",component.getProperty("DTSTART").getValue());
 Log.d("RRULE 4: DTEND: ", component.getProperty("DTEND").getValue());
.......

above is the snippet of my code and i got the following results

D/RRULE 1:: RRULE
D/RRULE 2:: FREQ=DAILY;COUNT=184
D/RRULE 3: DTSTART:: 20160701T170000
D/RRULE 4: DTEND:: 20160701T200000 

I don't know how to parse all the events from FREQ ?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

1

You can use our library lib-recur.

The (very) basic usage (not accounting for time zones) would be as follows:

RecurrenceRule rule = new RecurrenceRule(component.getProperty("RRULE").getValue());
DateTime start = DateTime.parse(component.getProperty("DTSTART").getValue());
int maxInstances = 100; // limit instances for rules that recur forever
RecurrenceRuleIterator it = rule.iterator(start);
while (it.hasNext() && (!rule.isInfinite() || maxInstances-- > 0))
{
    DateTime nextInstance = it.nextDateTime();
    // do something with nextInstance
}

The library also supports multiple RRULEs, EXRULEs, EXDATEs, RDATEs and time zones.

Marten
  • 3,802
  • 1
  • 17
  • 26
  • Thanks @Marten , I have found another library. However that library didn't give me the End date of the recurring event, can i get it by using your library? e,g Recurring event daily from 01/Feb - 30/Feb ; Start time 11:00 pm - End Time 01:00 am, can i get the end dates of events? as in this case the Start date and End date would not be same of an event. – Moin Uddin Kashif Feb 16 '17 at 17:27
  • Our library can only tell you the start of the last event in the recurrence set. But you can just add the number of milliseconds between start and end to that to get the end of the last event. – Marten Feb 17 '17 at 14:16