# Fixes

## 1. Renewal dates rolling into the wrong month (Jan 31 → "March 3")

**Cause:** `addMonths` in `src/dates.js` used `Date.setUTCMonth()`. When the start
day does not exist in the target month, JavaScript overflows into the next month:
Jan 31 + 1 month becomes "Feb 31", which is normalised to March 3 (March 2 in leap
years). The same happened for quarterly/annual plans, e.g. Nov 30 + 3 months → Mar 2,
and Feb 29 + 12 months → Mar 1.

**Change:** `addMonths` now computes the target year/month and clamps the day to the
last day of that month. Jan 31 + 1 month → Feb 28 (Feb 29 in leap years), May 31 +
3 months → Aug 31, Feb 29 2028 + 12 months → Feb 28 2029. Dates whose day exists in
the target month are unchanged. `daysUntilRenewal` uses the same helper, so reminder
countdowns are fixed too.

Note: renewals are computed from `lastPaid`, so a monthly member who joined on the
31st and pays on Feb 28 will next renew on Mar 28. That follows the existing
"one billing period after the last payment" rule; if the association wants such members
anchored to the end of the month, that is a policy change to `renewalDate`, not part of this fix.

## 2. Wrong multi-year discount

**Cause:** `multiYearDiscount` in `src/membership.js` picked a tier with
`years > t.years` instead of `years >= t.years`. A 3-year prepay therefore only matched
the 2-year tier (5% instead of 10%), a 2-year prepay got no discount, and the 10% tier
only kicked in from 4 years.

**Change:** The comparison is now `>=`. 2 years → 5%, 3+ years → 10%. Example: a small
shop prepaying 3 years is now invoiced $499.50 (was $527.25).

## Tests

Added `test/fixes.test.js` covering month-end clamping (monthly, quarterly, annual, leap
years, year boundary), the reminder day count for a Jan 31 member, discount tiers at
exactly 2 and 3 years, and multi-year invoice totals. `node --test`: 11/11 pass.
Public function signatures are unchanged.
