IRS says:
The term ‘period of nonqualified use’ does not include any portion of the five-year period described in subsection (a) which is after the last date that such property is used as the principal residence of the taxpayer or the taxpayer’s spouse.