Menu

#17 finding next event after a given time

open-postponed
nobody
None
5
2007-02-25
2006-12-05
No

This seems like a fairly fundamentally useful thing to be able to do - for instance to calculate the next upcoming event in order to trigger an alarm, or in my case to use an icalendar file to drive a scheduler (I'm writing a Quartz scheduler trigger which will enable Quartz scheduler to be driven by an iCalendar file). At the moment I can't find any functionality like this in iCal4J. It's hard to implement any functionality like this from *outside* the library, because although you can do VFreeBusy searches it's not really possible to know how to bound a search, or to retrieve the actual events themselves.

I've written a patch which adds functionality to VEvent and Recur to return the next occurrence of an event after (or simultaneous with) a given time. The VEvent.getNextOccurrence(Date) method returns a Period object (or null) for the next occurrence at the given time. If an event is in progress at the given time then it will return the period of the event in progress. It seems to handle most types of baroque recurrence rules I can throw at it, however I'm not an iCalendar expert (2 days experience so far) so I'm a bit vague about whether a single VEvent can legally have simultaneously occurring overlapping recurrences - if so then the current implementation doesn't handle this case.

I've also done a patch for Calendar which will return the next "boundary points" after a given time. "Boundary points" are the start or end points of events. This enables you to find out the next thing that's going to happen in a particular calendar. The method returns Boundary objects, each of which contains the time of the boundary point along with the Event that is associated with it and information about whether the Boundary is the Start or End of an event occurrence. The Calendar.getNextBoundary(Date) method actually returns an array of Boundary objects, rather than a single Boundary since it's possible that multiple boundary events happen at the same moment. It seems to handle any cases I can think of at the moment (except multiple parallel recurrences of a single Event as described above).

I've also included a patch with a reasonable amount of tests which cover all the cases I can think of.

Discussion

  • Joshua Portway

    Joshua Portway - 2006-12-05

    Logged In: YES
    user_id=54791
    Originator: YES

    File Added: getNextOccurrence-tests.patch

     
  • Joshua Portway

    Joshua Portway - 2006-12-09

    Logged In: YES
    user_id=54791
    Originator: YES

    File Added: srcdiff.patch

     
  • Joshua Portway

    Joshua Portway - 2006-12-09

    source code diff with fix for simple events

     
  • Joshua Portway

    Joshua Portway - 2006-12-09

    tests patch with added test for simple (no recur) events

     
  • Joshua Portway

    Joshua Portway - 2006-12-09

    Logged In: YES
    user_id=54791
    Originator: YES

    File Added: testdiff.patch

     
  • Joshua Portway

    Joshua Portway - 2006-12-09

    Logged In: YES
    user_id=54791
    Originator: YES

    The last patch had a stupid bug which meant it wasn't working with simple (non-recurring) events. I've uploaded a new patch which fixes this bugs and adds a unit test for it.

     
  • Ben Fortuna

    Ben Fortuna - 2006-12-10
    • status: open --> pending-rejected
     
  • Ben Fortuna

    Ben Fortuna - 2006-12-10

    Logged In: YES
    user_id=14058
    Originator: NO

    Hi Joshua,

    Thanks for taking the time to contribute this. There's quite a lot to digest here, so forgive me if I miss something. :)

    Something you may not have seen just yet is that the iCalendar specification actually includes support for triggering alarms on calendar components. The relevant sections are as follows:

    http://rfc.net/rfc2445.html#s4.6.6

    http://rfc.net/rfc2445.html#s4.8.6

    http://rfc.net/rfc2445.html#s4.2.14

    So it is possible to implement a (Quartz) scheduler that runs at a pre-defined interval to process an iCalendar file and trigger the alarms specified in the file itself. The benefit of this approach is that you will be able to support triggering alarms that have been defined in other CUAs (e.g. Outlook, Lotus Notes, etc.) as long as they specify the alarm triggers appropriately (I'd assume they would).

    To implement such a scheduler you would need to do something like this:

    - retrieve all alarms from VEVENT and VTODO components (the only components that support alarms), via the VEvent.getAlarms() and VToDo.getAlarms() methods.

    - for each alarm retrieve the TRIGGER property (VAlarm.getTrigger()) to identify whether the alarm should trigger in the current scheduler cycle. Note that a trigger may be specified as either an absolute time or relative to the component start/end (this is equivalent to your concept of Boundaries).

    - the iCalendar file can even specify what to do when an alarm is triggered, via the ACTION property. By default this supports playing a sound, display an alert (e.g. dialog box), sending an email, or performing some other procedure as defined by an associated attachment (ATTACH property). Note that you can also define your own actions if the default actions don't support what you want to do.

    So running such a scheduler at a specified interval (say, 15 minutes) should achieve the same result, but in a standard way, which means you will automatically support iCalendar alarms created in other applications.

    I think there is potential for iCal4j to make it easier to create such a scheduler (e.g. provide support for identifying if an alarm should trigger in the current scheduler interval), but I would like to base such support on the built-in alarms/triggers support in the iCalendar specification.

    regards,
    ben

     
  • Nobody/Anonymous

    Logged In: NO

    Hi Ben,
    I considered using alarms, but they don't provide exatly the functionality I'm after. My application isn't really just for calendaring - I'm using iCalendar format files to allow users to specify what media should be played on a video playback system. The idea is to allow the user to schedule "MovieA" to be played between 1am and 4pm each day, and "MovieB" to be played every friday at 5pm etc.

    Alarms only really specify moments in time that the alarm should trigger - as far as I can tell they don't specify spans of time. So alarms don't really seem appropriate for this. Also, in every calendaring application I can find, alarms are an optional extra appended to an event - my users would have to make their "play a movie" event and then manually attach an alarm to it which would be very awkward.

    More generally, the functionality I've implemented in this patch is useful for other things than triggering alarms. These patches are really about being able to query a calendar to find out what's going on at a particular point in time. The ability to return the start and end times of the next occurrences of an event would be pretty essential to rendering the calendar in a timeline for instance. Another example might be a meeting room booking application - it would obviously be desirable to be able to query the calendar to find out who was in each room at any given point in time.

     
  • Ben Fortuna

    Ben Fortuna - 2006-12-18

    Logged In: YES
    user_id=14058
    Originator: NO

    Hi Joshua,

    Have you seen the filtering API included with iCal4j (net.fortuna.ical4j.filter)? Filters are quite useful for identifying a subset of calendar events that conform to specific properties/values. e.g:

    http://wiki.modularity.net.au/ical4j/index.php?title=Examples#Filtering_events

    I believe that filters can be used to provide similar functionality, with regard to querying a calendar to identify what is happening at a particular point in time. Currently the filter API is very basic, but I expect it to be extended when I can find some more appropriate use cases.

    I'm not completely disregarding the work you have done here, but just want to be sure of the value added before I include changes to the API. For example, if similar functionality can be achieved by another existing means I would prefer to not provide yet another alternative approach as it will end up confusing as to which approach is recommended.

    So I am still interested in finding a way to include your functionality, but just need some time to analyse it to see where it will fit best. It is also helpful to hear your point of view with regard to how this provides functionality not possible with other approaches, as you have done already.

    Thanks again.

    regards,
    ben

     
  • Ben Fortuna

    Ben Fortuna - 2006-12-18
    • status: pending-rejected --> pending-postponed
     
  • SourceForge Robot

    Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).

     
  • SourceForge Robot

    • status: pending-postponed --> closed-postponed
     
  • Ben Fortuna

    Ben Fortuna - 2007-02-25
    • status: closed-postponed --> open-postponed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.