I am trying to solve some kind of a math problem here... The particular use-case is not a mathematical one, but it boils down to a maths issue. I'm trying to figure out how to tell if two recurring events collide in time.
Event 1 takes place on the 1st week, then it doesn't happen for 2 weeks, then it happens again (1st, 4th, 7th, 10th, 13th, 16th, 19th, 22th, etc.)
Event 2 takes place on the 2nd week, then it doesn't happen for 4 weeks, then it happens again (2nd, 7th, 12th, 17th, 22th, etc.)
As you can see, these events sometimes happen on the same week: 7th, 22th, etc.
The problem here is that I have 3 variables:
- difference in weeks between the first and the second event (in this example, the difference is equal to 1)
- what is the repeat schedule of each of the two events: once a week, once every 2 weeks, once every 3 weeks, etc. (in this example, Event 1 happens once every 3 weeks; Event 2 happens once every 5 weeks)
Obviously, there are two certain conditions that can be moved away:
- having a difference of 0 weeks (means that the events occur on the same day, so practically they collide)
- having a repeat schedule of "once a week" for at least one event
NOTE: The events are recurring and some may not have an ending date, meaning they could last forever.
What I'm trying to achieve here is tell whether the events will occur in the same week. Ever.