calculate the time to wait