The stability of ecosystems—A finite-time approach