Generating trigger instances

Generating absolute triggers is trivial; you just use the date and time they specify. However, relative triggers are associated to recurrence instances, so in order to generate trigger instances we must generate the corresponding recurrence instances and compute the trigger times based on those.

Since relative triggers are specified as occurring a certain amount of time before or after each of a calendar component's recurrence instances, we can compute a trigger time by adding or subtracting that amount of time to the corresponding recurrence instance's time.

Recurrence instances are generated by specifying a range of time and asking the Wombat to generate the instances that occur within that range. We shall see that the range of time in which instances occur is not necessarily the same range of time in which those instances' alarm triggers occur.

Consider an alarm that is set to trigger 10 minutes before the start time of an event's occurrence, that is, the trigger has an offset of -10 minutes. Say this event recurs every hour at 5 minutes past the hour: it would occur at 1:05, 2:05, 3:05, etc.; the corresponding triggers would occur at 12:55, 1:55, 2:55, etc. If we wish to compute the alarm triggers that occur between 4:00 and 6:00 (which would be at 4:55 and 5:55), then we cannot just generate recurrence instances between 4:00 and 6:00 because we will miss the 6:05 occurrence which corresponds to the 5:55 trigger.

The solution is to expand the range of time on both sides to fit the relative triggers that have the largest time periods. If a trigger's offset is negative, like the -10 minutes in the example above, then we must expand the end of the time range: in the case above, the range's ending time of 6:00 must be grown by 10 minutes to 6:10 so that the last recurrence instance will be that of 6:05; computing the trigger's offset we will get the 5:55 trigger, which is what we wanted. For triggers with positive offsets, like if an alarm were to trigger 20 minutes after an event's occurrence, we must expand the start of the time range in an analogous way, by subtracting the time offset from it.

Again, absolute triggers need no special computation. We can just see if the trigger time is within the requested range of time, and if so, we take that trigger occurrence into account for the final result.

In addition, alarms may specify a number of repetitions and a duration time. For example, an alarm may be configured to repeat 3 extra times after the original occurrence with 5 minutes between each repetition. Again, for absolute triggers this does not present a problem, as we can just generate the repetitions starting from the absolute trigger time. For relative triggers, we expand the range as described above and also add the total offset for the repetitions to the start of the range, i.e. 15 extra minutes for the case of 3 repetitions with 5 minutes between each. We do not need to modify the end of the range because alarm repetitions always have positive offsets, so they are equivalent to relative alarm triggers with positive offsets.