How to calculate shift hours in postgres?
Assuming your status is consistent, i.e. always comes in pairs you could do something like:

select dt, employee_id, min_tm, max_tm, sum(delta_tm)
from (
    select dt
         , employee_id 
         , min(tm) over (partition by employee_id,dt) as min_tm
         , max(tm) over (partition by employee_id,dt) as max_tm
         , tm - lag(tm) over (partition by employee_id,dt order by tm) delta_tm
         , status
    from t
) as u 
where status = 'O'
group by dt, employee_id, min_tm, max_tm;