fjsj
fjsj

Reputation: 11250

Detecting overlapping date recurrence rules

I'm working in a application that looks like Google Calendar, but with one main difference: events shouldn't have intersections with other events. This means that no two events may share common time, even in minutes granularity. This is specially useful for a calendar that only store meetings, since it is impossible to be at the same time in two meetings.

Just like Google Calendar, events may be created by using recurrence rules (every friday and sunday from 10 AM to 13 PM, for example). So I would like to detect overlapping events by only using rrules (of python-dateutil module), without needing to create N datetime objects and checking for intersection against each one.

Is it possible to detect overlapping dates by only using rrules? Is there anything similar already implemented in another library?

Upvotes: 5

Views: 2089

Answers (1)

Malcolm Box
Malcolm Box

Reputation: 4036

No, I don't believe it's possible to analyse a rrule to see if it can intersect another one without creating the datetime objects.

Essentially you're asking for the output of an algorithm without running the algorithm, and I think that's non-computable.

However, for certain types of rrule it is possible - e.g. a rrule of every Thursday can't intersect a rrule for every Tuesday. The problematical ones are days of the month and days of the year intersecting with days of week, and frequencies that never intersect.

The best bet would be to do the rules that are analytically checkable analytically, then for others generate the next year or so's data and compare manually.

The algorithm can run fast, since you can cache the existing occupied times as you add each rule.

Upvotes: 6

Related Questions