I had one ex, we were together for two years, didn't see each other for 6 months and then had additional 2 years of casual sex and going out.
I think the time needed depends on how it all "ended". I don't think that it ever ends. Somebody that has been part of your life for so long, shared such amazing moments with can't just be forgotten, erased from our existence.
It is however hard to let them back into your life, depending on how strong the trust break was. In my case, there was barely any break of trust so it was relatively easy to become friends again.
In a case where the relationship ends, for example, due to someone cheating, the break of trust is pretty strong and it will take longer to forgive (unless you realize that the majority of us are forced into monogamous relationships while many are actually polyamorous).