简体   繁体   English

评估 iCal `event` 当前是否正在进行中

[英]Evaluate if iCal `event` is currently in progress

Im currently using a library called biweekly to parse iCal events in java.我目前使用一个名为biweekly的库来解析 java 中的 iCal 事件。 I have no issue swapping libraries if a better solution is present so all java related solutions would be welcome.如果存在更好的解决方案,我没有问题交换库,因此欢迎所有 java 相关解决方案。

Im trying to create a function that checks an iCal schedule to work out if any events are currently in progress / active .我正在尝试创建一个 function 来检查 iCal 时间表以确定当前是否有任何事件in progress / active

Biweekly helped cleanly parse the iCal schedule events like this: Biweekly 帮助干净地解析 iCal 日程安排事件,如下所示:


List<ICalendar> icals = Biweekly.parse(schedule).all();

for (ICalendar ical : icals) {

    for (VEvent event : ical.getEvents()) {

        // I need to compute if the event is currently active

    }
}

We found an example that helps get the events as a DateIterator but we can't as yet connect that to knowing if an event is currently active.我们找到了一个示例,可以帮助将事件作为DateIterator获取,但我们还不能将其与知道事件当前是否处于活动状态联系起来。


TimezoneInfo tzInfo = ical.getTimezoneInfo();

DateStart dateStart = event.getDateStart();

TimeZone timezone;
if (tzInfo.isFloating(dateStart)){
    timezone = TimeZone.getDefault();
} else {
    TimezoneAssignment timezoneAssignment = tzInfo.getTimezone(dateStart);
    timezone = (timezoneAssignment == null) ? TimeZone.getTimeZone("UTC") : 
    timezoneAssignment.getTimeZone();
}

DateIterator it = event.getDateIterator(timezone);

As discussed in comments, it seems the method you're looking for is getStatus() of the class VEvent :正如评论中所讨论的,您正在寻找的方法似乎是 class VEventgetStatus()

/**
 * Gets the status of the event.
 * @return the status or null if not set
 * @see <a href="http://tools.ietf.org/html/rfc5545#page-92">RFC 5545
 * p.92-3</a>
 * @see <a href="http://tools.ietf.org/html/rfc2445#page-88">RFC 2445
 * p.88-9</a>
 * @see <a href="http://www.imc.org/pdi/vcal-10.doc">vCal 1.0 p.35-6</a>
 */
public Status getStatus() {
    return getProperty(Status.class);
}

GitHub documentation: https://github.com/mangstadt/biweekly/blob/master/src/main/java/biweekly/component/VEvent.java#L501 . GitHub 文档: https://github.com/mangstadt/biweekly/blob/master/src/main/java/biweekly/component/VEvent.java#L501

Be careful when you handle this value, according to the documentation it may be null so always null-check before doing whatever you think to do.处理这个值时要小心,根据文档,它可能是null所以在做任何你想做的事情之前总是检查空值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM