From f832138b41643d25b96e4461b191320fa4843443 Mon Sep 17 00:00:00 2001 From: Carlos Escalante Date: Fri, 3 Jul 2026 20:38:44 -0600 Subject: [PATCH] Pensions: compute current age from birthdate instead of hardcoded 30 FCL projection target defaults to the next 5-year withdrawal window (CURRENT_AGE + 5) rather than a fixed 35. Co-Authored-By: Claude Opus 4.8 (1M context) --- frontend/src/pages/Pensions.tsx | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/Pensions.tsx b/frontend/src/pages/Pensions.tsx index a68696f..0627d75 100644 --- a/frontend/src/pages/Pensions.tsx +++ b/frontend/src/pages/Pensions.tsx @@ -84,7 +84,17 @@ interface TooltipEntry { // ─── Constants ──────────────────────────────────────────────────────────────── -const CURRENT_AGE = 30; +const BIRTH_DATE = new Date(1988, 7, 29); // 29 de agosto de 1988 + +function computeCurrentAge(): number { + const now = new Date(); + const hadBirthdayThisYear = + now.getMonth() > BIRTH_DATE.getMonth() || + (now.getMonth() === BIRTH_DATE.getMonth() && now.getDate() >= BIRTH_DATE.getDate()); + return now.getFullYear() - BIRTH_DATE.getFullYear() - (hadBirthdayThisYear ? 0 : 1); +} + +const CURRENT_AGE = computeCurrentAge(); const FUND_KEYS: FundKey[] = ['FCL', 'ROP', 'VOL']; @@ -99,7 +109,7 @@ const FUNDS_DEFAULT: Record = { annualRate: 7.5, isDividend: false, withdrawalRule: 'Retirable cada 5 años o al cambio de empleo', - defaultTargetAge: 35, + defaultTargetAge: CURRENT_AGE + 5, }, ROP: { key: 'ROP', @@ -255,7 +265,7 @@ const EMPTY_SNAPSHOTS: PensionSnapshot[] = []; export default function Pensions() { const [visibleFunds, setVisibleFunds] = useState>(new Set(FUND_KEYS)); const [projections, setProjections] = useState>({ - FCL: { contribution: 150_000, rate: 7.5, targetAge: 35 }, + FCL: { contribution: 150_000, rate: 7.5, targetAge: CURRENT_AGE + 5 }, ROP: { contribution: 120_000, rate: 6.0, targetAge: 65 }, VOL: { contribution: 400_000, rate: 8.0, targetAge: 57 }, });