Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse an iCal RRULE in Java [closed]

I have the following iCal recurrence rule examples:

"RRULE:FREQ=YEARLY;INTERVAL=2"
"RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,TH"

I need a Java library to parse the RRULE patterns to handle in an object. Are there any good Java libraries?


  • ical library does not build correctly;
  • google ical implementation is not supported for ages;
  • maven repository can propose a lot of implementations, but I did not got any actual one.
like image 589
Sergii Avatar asked Apr 10 '17 09:04

Sergii


2 Answers

You can use lib-recur

It is still supported and handle RFC 5545 and RFC 2445.

RecurrenceRule rule = new RecurrenceRule("FREQ=YEARLY;BYMONTHDAY=23;BYMONTH=5");

DateTime start = new DateTime(1982, 4 /* 0-based month numbers! */,23);

RecurrenceRuleIterator it = rule.iterator(start);

int maxInstances = 100; // limit instances for rules that recur forever

while (it.hasNext() && (!rule.isInfinite() || maxInstances-- > 0))
{
    DateTime nextInstance = it.nextDateTime();
    // do something with nextInstance
}

You can install it with maven

<!-- https://mvnrepository.com/artifact/org.dmfs/lib-recur -->
<dependency>
    <groupId>org.dmfs</groupId>
    <artifactId>lib-recur</artifactId>
     <version>0.10.2</version>
</dependency>

Or with gradle

// https://mvnrepository.com/artifact/org.dmfs/lib-recur 
compile group: 'org.dmfs', name: 'lib-recur', version: '0.10.2'

More documentation is available here : https://github.com/dmfs/lib-recur

like image 193
Ckram Avatar answered Nov 03 '22 15:11

Ckram


The solution is to use:

        <dependency>
            <groupId>org.scala-saddle</groupId>
            <artifactId>google-rfc-2445</artifactId>
            <version>20110304</version>
        </dependency>

Few examples:

1 convert to java object:

rule = new RRule("RRULE:FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,TH");

2 convert back:

rule.toIcal();
like image 25
Sergii Avatar answered Nov 03 '22 13:11

Sergii