improved #to_time logic