Fix logic of endTime for corner cases