Create convert_time() function to reduce redundancy of code