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?
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question