3

I'm trying to use the ical4j library to find the current event (or at least events occurring today) in an ical file that contains recurring events. I've managed to build and print all events in the calendar but I have been getting

java.lang.IllegalArgumentException: Range start must be before range end

at runtime. This is strange because my period rule clearly starts before it ends. I have done a lot of reading and trying different things but I'm clueless. Here's the gist of what I'm trying to achieve:

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));

Any help would be appreciated. Thanks.

0 Answers0