diff --git a/lib/utils/billing_cost_util.dart b/lib/utils/billing_cost_util.dart index 6ef26a5..25e0480 100644 --- a/lib/utils/billing_cost_util.dart +++ b/lib/utils/billing_cost_util.dart @@ -214,20 +214,20 @@ class BillingCostUtil { // 결제 주기에 따른 개월 수 final cycleMonths = _getCycleMonths(normalizedCycle); - // 결제 발생 월 계산 (nextBillingDate 기준으로 역산) - final billingMonth = nextBillingDate.month; + // 연도+월을 포함한 개월 차이 계산 + // nextBillingDate와 target 월 사이의 차이가 cycleMonths의 배수인지 확인 + final targetStart = DateTime(targetYear, targetMonth, 1); + final billingStart = + DateTime(nextBillingDate.year, nextBillingDate.month, 1); - // 대상 월이 결제 발생 월과 일치하는지 확인 - // 예: 연간 결제(1월), targetMonth = 1 → true - // 예: 연간 결제(1월), targetMonth = 2 → false - for (int i = 0; i < 12; i += cycleMonths) { - final checkMonth = ((billingMonth - 1 + i) % 12) + 1; - if (checkMonth == targetMonth) { - return true; - } - } + final monthDiff = (billingStart.year - targetStart.year) * 12 + + (billingStart.month - targetStart.month); - return false; + // monthDiff가 cycleMonths의 배수이면 해당 월에 결제 발생 + // 예: 연간 결제(2027-01), target=2026-01 → monthDiff=12, 12%12=0 → true (이전 결제) + // 예: 연간 결제(2027-01), target=2026-02 → monthDiff=11, 11%12≠0 → false + // 예: 연간 결제(2027-01), target=2027-01 → monthDiff=0, 0%12=0 → true + return monthDiff % cycleMonths == 0; } /// 결제 주기별 개월 수 반환