• I believe what you have is a classic gaps and islands problem for which there have been many articles written. This search will point you to a few articles that should point you in the right direction.

    Had you posted some more example data with your expected outcomes as mentioned in the first link in my signature I would have provided some code, but due to the time it would take to mock up an example, I can't do that right now.

    Also you mention shifts, does this mean that you want downtime broken down by shift or by day?