Calculation of distance and time