Algorithm: How to check intersection definitions of recurring events?

The question arises from the behavior of the MS Outlook calendar.

Imagine that I have two recurring events (starting today): "every second Monday" and "every odd date." Is there a way to check for intersections and / or find the first intersecting date algorithmically without roughly forcing each date?

Definitions can be made in the CRON notation or in the ICal notation. I think it doesn’t matter.

Are there any solutions for this in the Gregorian calendar?

UPD . It is also interesting to learn how MS Outlook Calendar handles these events. I mean how he finds out about it. are there two events today? I assume this is also a method of determining whether a particular date is suitable for determining a recurring event.

Formally, it can be described as two functional algorithms:

Date:intersection(Event e1, Event e2) boolean:contains(Date date, Event ev) 

As for the limitations, we can move on to designating the definition of an event. You can see in Outlook (or iCal) that you can identify a less complex view of a recurring event.

+7
date algorithm
source share
2 answers

Since the period for the first repetition is 14 days, the parity (odd or even) of the day will change only if the month ends with an odd number: January, February, March, May, July, August, October, Dec. Within a month it will not change.

+1
source share

If you are only concerned about the event that events from different recurring events occur on the same day, you can:

  • Set some arbitrary day in the recent past as day 1.
  • Express each repetition as the "number of days" between events and the start day; if your event occurs every Monday and every Thursday, then express it as 2 repetitions with 2 starting days.
  • Use the appropriate modular arithmetic to find the days when events from different relapses collide.

For example, if the repetitions “every Monday” and every “fifth day” collide on the first day, they will follow on the 36th, 71st, 106th, etc. days

If you need something more accurate, you will need to measure not for whole days, but no matter what part of the day you are interested in.

+1
source share

All Articles