إِنَّمَا ٱلتَّوْبَةُ عَلَى ٱللَّهِ لِلَّذِينَ يَعْمَلُونَ ٱلسُّوٓءَ بِجَهَـٰلَةٍ ثُمَّ يَتُوبُونَ مِن قَرِيبٍ فَأُو۟لَـٰٓئِكَ يَتُوبُ ٱللَّهُ عَلَيْهِمْ ۗ وَكَانَ ٱللَّهُ عَلِيمًا حَكِيمًا Qur’an An-Nisaa' (4:17)Innama alttawbatu AAala Allahi lillatheena yaAAmaloona alssooa bijahalatin thumma yatooboona min qareebin faolaika yatoobu Allahu AAalayhim wakana Allahu AAaleeman hakeeman
The expression min qarib, which here implies nearness in time, could also be rendered as "soon", i.e., soon after having committed the evil deed; most of the classical commentators however, hold that in this context it denotes the time before the actual approach of death. This interpretation is borne out by the next verse.
A person’s repentance will be accepted as long as they repent any time before their death. But one should not procrastinate because they do not know when they will die.