Why isn't C10 15:00? Assuming that's right try this formula in C2 copied down

=D2-(B2<A2)*3/8-MEDIAN(B2,"9:00","18:00")+MEDIAN(A2,"6:00","18:00")