This seems to work in the latest sample workbook (and is my last contribution):
=IF(N4-INT(N4)=(L4/24),0,IF(AND(N4-INT(N4)>G4-INT(G4),G4-INT(G4)>=6/24),0,IF(G4>N4-INT(N4),MAX(N4,22/24)-MAX(G4,22/24),0)))
It's up to you to tweak it further if you find circumstances that fail - this is for your...