After refactoring the code to understand it & adding a test this is the upshot...
we are dealing with annual memberships (even if they are in 5 year blocks rollover is
still about month & day) so if the definition of whether they are in the rollover period is
actually the same in multi-year as for a single year - if they are between the rollover &
the cut off they get an extra part-year. Hence, when determining whether to give an extra
part year we don't need to compare the rollover to the final end date (5 years on) but
to the next year's end date - just like for an annual
Note that one could argue, but I don't think anyone has, that if the 5 year period has started
then the get the remainder of this 5 years + the next 5 years - which is what the
existing code seems to be almost trying to do
$endDateOfFirstYearMembershipPeriod = date('Y-m-d', mktime(0, 0, 0,
$dateParts[1],
$dateParts[2] - 1,
- $dateParts[0] + ($numRenewTerms * $membershipTypeDetails['duration_interval'])
+ $dateParts[0] + 1
));
//we know the month and day of the rollover date but not the year (we're just