I'm looking for an algorithm to convert several date-ranges to their 'base' ranges.
This base level means, it has the lowest number of seperate date-ranges. So overlapping or back-to-back ranges should be merged to one range.
With two ranges the comparison is fairly simple:
if (endA >= startB && endB >= startA) > Overlap and merge them
But what if the mergedAB backs against a third daterange C...
A: 2 April - 10 April
B: 5 April - 14 April
C: 15 April - 25 April
D: 28 April - 1 May
Then this should result in:
2 April - 25 April
28 April - 1 May
Any pointers on how to tackle this algorithm? How do I determine the end of the itteration, eg when is the base reached??