We have a system that stores event information.There is a primary list of events as well as a secondary list, these may overlap.Secondary lists are combined with the primary based on 3 main rules.Default - only displayed when no events are currentEvents - only displayed when primary events are currentOverride - displayed in stead of eventsA new 3rd party system we have to integrate with means we need to get each of the different states throughout the days of what events/secondary events should be showing.Eg, from 9-5 these events are current based on the timings/ rules, but then after 5 these events are current based on the timings and rules.A simple examplePrimary EventsEvent alpha | 10:30 - 14:30Event bravo | 14:00 - 16:00Event charlie | 18:30 - 20:00Secondary EventsEvent zulu | 00:00 - 23:59 | defaultEvent yankee | 09:00 - 11:00 | defaultEvent xray | 09:00 - 11:30 | eventsEvent whiskey | 19:00 - 19:15 | overrideJust on this very small example this would result as the following lists that we would need to generate00:00-09:00Event zulu09:00-10:30Event zuluEvent yankee10:30-11:30Event alphaEvent xray11:30-14:00Event alpha14:00-14:30Event alphaEvent bravo14:30-16:00Event bravo16:00-18:30Event zulu18:30-19:00Event charlie19:00-19:15Event whiskey19:15-20:00Event charlie20:00-23:59Event zuluThis is a tiny example in production there is usually hundreds to thousands of events over many days. At present the only end points deal with this problem dynamically on the fly, this third party system requires we provide the data in this way.It's all written in php, and we have the primary and secondary event lists in an array each.What is the most efficient way of making these lists ?We have considered doing a minute by minute check, but this seems horribly inefficient and I'm hoping there is a better way. 
How to efficiently determine when changes occur in event lists
php;sorting
So heres what I did in the end, rather than looping through each minute of each day and checking what should be showing I created a list of all the start and stop times (in one single list) then removed duplicates and sorted them in order. This way I can just cycled through that array and that will give me the start/end times when things change. 