added the logic to calculate the time.