mangstadt / biweekly

biweekly is an iCalendar library written in Java.
BSD 2-Clause "Simplified" License
323 stars 44 forks source link

Evaluate if `event` is currently in progress #119

Closed tarkal closed 2 years ago

tarkal commented 2 years ago

Is there a function to determine if an event is currently in progress?

Looking for something like this:

boolean inProgress = event.isInProgress(TimeZone timezone);

If this is not something that you feel would be useful in the library can you point us in the right direction?

This is what I have written but not tested;

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

            for (ICalendar ical : icals) {

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

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

                    it.advanceTo(new Date());

                    Date date = it.next();

                    // Note sure if this date is the start date. I need a way to check if its in range

                }
            }