There are multiple recurring intervals of time, starting from a startTime to an endTime. Each interval is defined by the start time of the recurrence, the end time (till the point where the recurrence is going to continue), the onDuration (when it is active, and can overlap), and the offDuration.
Sample Interval:
startTime: 3 secs
endTime: 30 secs
onDuration: 3 secs (represented by x)
offDuration: 5 secs (represented by -)
|--[xxx]-----[xxx]-----[xxx]-----[xxx]-|
Overlapping Intervals: Two recurring series are said to overlap if they have overlapping on-times (x) within the start and end time ranges of each of them.
Question: There are tens of such intervals. A new recurring interval, defined by the same parameters (startTime, endTime, onDuration, offDuration) is provided. Does this new recurring interval overlap with any of the existing intervals, within the time ranges of startTime and endTime?
PotentialInterval:
startTime: 6 secs
endTime: 15 secs
onDuration: 3 secs
offDuration: 6 secs
PotentialInterval does not conflict with SampleInterval because it ends before it would have overlapped.
Notes:
This is very similar to this question, but I couldn't completely understand the correctness of the solution. Also, I'm interested in only determining whether they conflict (boolean true or false), rather than the actual conflicting interval.
Both the end time and start time of each interval form an arithmetic progression. startTimen = startTime + (n-1) (onDuration + offDuration) where startTimen < endTime. Thus, maybe this question might point in the right direction, though I couldn't find a way to incorporate durations in this.
The samples are much smaller. In reality, the number of individual intervals in each recurrence would be several thousands (for eg, from now till next 10 years every day from 3PM to 4PM). Also, the number of recurrences could be hundreds. Thus, denormalizing the data (making a list of each occurence) may not be practical.
This data is stored in a NoSQL database, so date-time manipulations within the database are not possible. This needs to be done in memory, and preferably in the order of ~500 milliseconds