optimized logic in is_time_in_interval_R and used it in the code