Merge time intervals

(doesn't cover all the cases yet) :(