Translation:Mishneh Torah/The Book of Wisdom/Laws of Repentance/Chapter Two
(1) Which is complete repentance? One who had the same opportunity as when he sinned, and it is possible for him to do so, and he withdrew and did not do it because of his repentance; not from fear and not from weakness of strength. How? One who came unto a women in sin, and afterward in time he was secluded with her, and he remains in his love of her and in the strength of his body and in the province in which he sinned, and he withdrew and did not sin – this is a man of complete repentance. This is what Solomon said: "And remember your Creator in the days of your youth" (Ecclesiastes 12:1).
And if he only repented in the days of his old age, and in a time that he it is not able to do what he has done – although it is not superb repentance, it is helpful for him and he is a repentant. Even if he sinned all of his days, and he repented on the day of his death, and he died with his repentance, all of his sins are forgiven, as it says: "As long as the sun will not darken, and the light and the moon and the stars, and the clouds return after the rain" (ibid. 12:1)