Once the expiry date is calculated (based on how the membership is set up), the code then looks at the 'advance days' and if the expiry date calculated is less than the user's existing expiry date, plus the 'advance days', then one year is added to the new expiry date.

If a user did not have a previous membership then the calculated expiry date becomes the user's expiry date, unless they client uses 'calcExpiryDate', then, same as above. if the calculated expiry date + the advance days is before today, then one year is added to the expiry date.

For example, if you have 'own date' set at aug 31 and advance days is 30. So anyone buying a membership in August will have an expiry date as Aug 31, 2015. But if they buy in July, then the expiry date remains at Aug 31, 2014.