timetable icon indicating copy to clipboard operation
timetable copied to clipboard

Support Recurring event

Open tuyen-vuduc opened this issue 3 years ago • 1 comments

Hi,

Recurring event is very popular in our life.

Do we have any plan to support this?

tuyen-vuduc avatar Feb 19 '21 02:02 tuyen-vuduc

Supporting recurring events in Timetable directly is out of scope. You can, however, use my package rrule to calculate occurrences of recurring events in a given time frame using recurrenceRule.getAllInstances(…), and then wrap each occurrence in its own event that is returned to Timetable. (It might make sense to cache the calculated occurrences using recurrenceRule.shouldCacheResults.)

For example, using the new 1.0.0 pre-releases of Timetable, you could do something like this (not tested):

return TimetableConfig<BasicEvent>(
  eventProvider: (interval) {
    return myEvents.expand((event) {
      // For each recurring event, we calculate all instances that intersect the requested interval:
      final instances = event.recurrenceRule.getAllInstances(
        start: event.start - event.duration,
        after: interval.start,
        includeAfter: true,
        before: interval.end,
        includeBefore: true,
      );
      // From each instance, we create a separate event for Timetable:
      return instances.map((it) => event.copyWith(
            id: '${event.id}-$it',
            start: it,
            end: it + event.duration,
          ));
    });
  },
  // Other properties…
);

JonasWanke avatar Aug 07 '21 11:08 JonasWanke