Reorganize condition checking and validate end time too.