As Fletch said some workplaces require you to finish up in a certain time frame eg 6 weeks before EDD or require a letter from your doctor explaining when you can continue til.

With my first it was probably about 4 weeks (say 36weeks) before my EDD that I stopped although I didn't feel too bad just huffy puffy when walking too far and sick of crowded public transport but ended up having DS at 38.5 weeks so glad I didn't leave it too close.

These days though most employers and doctors seem pretty negotiable dependent on your medical situation. Have known lots of people that tried to hang on for as long as possible but when it got closer they were just too big tired and sore to be bothered going closer than 4/6 weeks. It really is an individual thing