如何用Java解析iCal RRULE [英] How to parse an iCal RRULE in Java

查看:539
本文介绍了如何用Java解析iCal RRULE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下 iCal重复规则示例:

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

我需要一个Java库来解析要在对象中处理的RRULE模式.有没有好的Java库?

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.

推荐答案

您可以使用 lib-recur

它仍然受支持并处理RFC 5545和RFC 2445.

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
}

您可以使用maven进行安装

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>

或带有gradle

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

更多文档可在此处获取: https://github.com/dmfs/lib-recur

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

这篇关于如何用Java解析iCal RRULE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆