Allah's Messenger (ﷺ) said, "If I stayed in prison as long as Joseph stayed and then the messenger came, I would respond to his call (to go out of the prison) ."
Sahih al-Bukhari Book 91, Hadith 11