creating the function to calculate the time