Longevity of moons around habitable planets