This is what the latest guidance notes say, so going by this it seems applying 28 days before the end of the qualifying period is ok?
5. When To ApplyYou and any children under 18 who are applying with you should apply before the end ofyour/their permitted stay in the UK when you are nearing completion of the qualifying periodrequired by the Immigration Rules.Please do not apply more than 28 days before completing that period. If you apply earlierthan that, your application may be refused. If that happens, we will not refund the fee andyou will have to pay again when reapplying.For visa holders only. If, after receiving your visa, you delayed your journey such that youwill reach the “valid until” date on your visa before completing 24 months/60 months in theUK, you may need to apply for an extension of stay to complete the 24 month/60-monthperiod before applying for indefinite leave to remain on form SET(M). An application for anextension of stay must be made on form FLR(M) or FLR(FP).