mavenicalendarrfc5545ical4jjfxtras

Finding vevents between date range


I am using jfxtras iCalendarAgenda in my application currently. I need to retrieve a list of events between a given date range from vcalendar. And I need it to return events with actual datetimes and not events that have recurrences that occur between the date range.

I have tried using ical4j and their filter library. Unfortunately I have been unsuccessful in trying to set up this plug in properly as it can not seem to find the dependencies that it needs. (I tried putting it and it's dependencies in my pom. Xml file). I also found a lot of recurrence rule parsers but it was unclear if they supported the other arguments in vevents that jfxtras was using such as recurrence ID and exdates. I also found that it might be possible to do this using a vfreebusy object but I can not find more info on this. Lastly I know that jfxtras must be doing this somewhere so it knows what to display but I cannot find where that is and I cant find a method that I could do this with from them.

Looking for a library that can do this or a link to how to set up ical4j. As it's very unclear how to set it up using maven.


Solution

  • I wrote iCalendarAgenda. It is accompanied with an iCalendar library, named iCalendarFX (also called icalendar-lib in my Github account), that will do what you want. I don't know if ical4j is capable.

    Using iCalendarFX, I would filter a stream of the Vevents from the VCalendar and filter for those that meet your requirements. It would be something like this:

    VCalendar vCalendar = VCalendar.parse(content); // replace with your vCalendar
        LocalDateTime startTime = null; // set somewhere
        LocalDateTime endTime = null; // set somewhere
        List<VEvent> eventsBetweenStartAndEnd = vCalendar.getVEvents().stream()
            .filter(e -> {
                LocalDateTime myStartLocalDateTime = LocalDateTime.from(e.getDateTimeStart().getValue());
                boolean isOnOrAfterStart = ! myStartLocalDateTime.isBefore(startTime);
                boolean isOnOrBeforeEnd = ! myStartLocalDateTime.isAfter(endTime);
                return isOnOrAfterStart && isOnOrBeforeEnd;
            })
            .collect(Collectors.toList());