I have a spreadsheet with a shift start time and a shift end time. What I'm trying to do is figure out how much time is spent between a time range during their shift.

For example, this is my working code:
=IF(OR(ISBLANK(C8),ISBLANK(D8)),0,IF(D8>=TIME(7,0,0),IF(C8<=TIME(7,0,0),IF(D8<=TIME(11,0,0),(D8-TIME(7,0,0))*24,(TIME(11,0,0)-TIME(7,0,0))*24),IF(C8>=TIME(11,0,0),0,IF(D8<=TIME(11,0,0),(D8-C8)*24,(TIME(11,0,0)-C8)*24))),0))
This checks and returns how much time of the shift is spent between 7AM and 11AM. The only issue I'm having with this is the overnight shift. I can't figure out how to make this code work and return a valid number if, say, the shift was 11PM-7AM, or 6PM-2AM.

If anybody could give me a hand with this I sure would appreciate it!!!