Skip to content
Bartek Górny edited this page Jan 18, 2011 · 1 revision

Modifying events which have persisted occurrences

The problem

A recurring events generates a series of occurrences. The occurrences are created on-the-fly, they are not saved. If an occurrence is modified or cancelled it is saved in database as a "persisted occurrence". Then when an event generates occurrences, those occurrences which have a matching persisted occurrence are replaced by them. The match is positive when the persisted occurrence is related to the same event then the "volatile" occurrence and the original start and end of the persisted occ is the same as in the volatile occurrence. Example:

  • a daily event which starts at 8am and ends at 4pm
  • a persisted occurrence of the event which starts at 9am on 2011-01-07
  • replaces occurrence which starts at 8am on 2011-01-07

The issue is, what should we do if a user modified the original EVENT? In such a case there is no match anymore, so if we add to the above:

  • the event start is changed to 8:30am
  • there is no matching occurrence to the persisted occurrence
  • on 2011-01-07 we have two occurrences, one at 8am and the other at 8:30am

Possible approaches

  • delete all persisted occurrences

If a user cancelled or modified an occurrence, he did so for a reason - because in that very day the occurrence had to differ from the standard. But if he decided to modify the whole chain, perhaps he should rethink his exceptions.

The drawback is exactly the same - he created the exception for a reason which he might not even remember at the moment.

  • leave everything as it is

This is the reverse - if he wants an exception, let it be. If by modifying the event he created duplicate occurrences, he should review the schedule and either delete the persisted occurrence or cancel the new volatile one.

  • preserve matches

Leave exceptions as they were (by modifying original start and end of persisted occurences), so that in the above case we still have one occurrence on 2011-01-07 starting at 8:30.

This is nice and clear as long as we talk about daily events, or about modifying only start/end time of the event. But if the user changed rule of the event, or moved it to another day, things are not as simple. For example, if we had a weekly event occurring every Monday, and one occurrence was cancelled, then the event was moved to Tuesday - should the Tuesday occurrence be cancelled? Probably not.

  • block modification of events which have persisted occurrences

Doesnt seem acceptable - I mention it only for completeness.

Proposed implementation

Assuming the basic period is day (which is true in most real-life scenarios - I, for instance, never used django-schedule to manage events occurring every second) we can safely say that if an occurrence is modified or cancelled, it is because that day is in some respect exceptional. The solution would then be to adjust start/end time of persisted occurrences to match start/end time of the mother-event, but leave the day unchanged (event if the day of the event changed).

This also has a drawback - consider the following scenario:

  • a user creates weekly event occurring every Monday
  • for one occurrence, he changes DESCRIPTION because that week something is different
  • then changes day to Tuesday

This will bring the description of the occurrence in question back to standard...