我正在尝试使用 ical4j 库在包含重复事件的 ical 文件中查找当前事件(或至少是今天发生的事件)。我已经设法在日历中构建和打印所有事件,但我得到了
java.lang.IllegalArgumentException: Range start must be before range end
在运行时。这很奇怪,因为我的经期规则显然在结束之前就开始了。我做了很多阅读和尝试不同的事情,但我一无所知。这是我要实现的目标的要点:
private class CurrentShow extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
//params come from execute() call, params[0] is url
InputStream is = null;
net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
try {
is = new URL(urls[0]).openStream();
CalendarBuilder builder = new CalendarBuilder();
try {
calendar = builder.build(is);
} catch (Exception e) {
}
for (Iterator i = calendar.getComponents().iterator(); i.hasNext(); ) {
Component component = (Component) i.next();
System.out.println("Component [" + component.getName() + "]");
for (Iterator j = component.getProperties().iterator(); j.hasNext(); ) {
Property property = (Property) j.next();
System.out.println("Property [" + property.getName() + ", " + property.getValue() + "]");
}
}
java.util.Calendar today = java.util.Calendar.getInstance();
today.set(java.util.Calendar.HOUR_OF_DAY, 0);
today.clear(java.util.Calendar.MINUTE);
today.clear(java.util.Calendar.SECOND);
// create a period starting now with a duration of one (1) day..
Period period = new Period(new DateTime(today.getTime()), new Dur(1, 0, 0, 0));
Filter filter = new Filter(new Rule[] {new PeriodRule(period)}, Filter.MATCH_ALL);
Collection eventsToday = filter.filter(calendar.getComponents(Component.VEVENT));
任何帮助,将不胜感激。谢谢。