From a3d0b06501783cc15c0d3d0305febacd8e131103 Mon Sep 17 00:00:00 2001 From: Mannu Date: Sun, 17 May 2026 14:57:51 +0530 Subject: [PATCH] fix(growth): show age in years+months format - Show age as "1y 4mo" instead of just months - Add formatAge helper function - Apply to Latest Reading and WHO card Co-Authored-By: Claude Sonnet 4.6 --- src/app/growth/page.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/app/growth/page.tsx b/src/app/growth/page.tsx index 87e5f78..3680bf6 100644 --- a/src/app/growth/page.tsx +++ b/src/app/growth/page.tsx @@ -44,6 +44,23 @@ interface Goal { targetDate?: string; } +function formatAge(birthDate: string, measurementDate?: string): string { + const birth = new Date(birthDate); + const now = measurementDate ? new Date(measurementDate) : new Date(); + const years = Math.floor((now.getTime() - birth.getTime()) / (1000 * 60 * 60 * 24 * 365)); + const months = Math.floor(((now.getTime() - birth.getTime()) % (1000 * 60 * 60 * 24 * 365)) / (1000 * 60 * 60 * 24 * 30)); + + if (years > 0 && months > 0) { + return `${years}y ${months}mo`; + } else if (years > 0) { + return `${years}y`; + } else if (months > 0) { + return `${months}mo`; + } else { + return "Newborn"; + } +} + export default function GrowthPage() { const { childId, child, familyId } = useFamily(); const { theme } = useTheme(); @@ -415,7 +432,9 @@ export default function GrowthPage() {
Latest Reading
-
{new Date(latest.measured_at).toLocaleDateString()}
+
+ {new Date(latest.measured_at).toLocaleDateString()} ({child ? formatAge(child.birthDate, latest.measured_at) : ""}) +
{velocity && (
@@ -480,8 +499,8 @@ export default function GrowthPage() { className="w-full p-4 flex justify-between items-center hover:bg-gray-50 dark:hover:bg-gray-700 transition-colors" >
-
{child.name} - WHO Standards
-
{ageMonths} months old
+
{child.name}
+
{formatAge(child.birthDate)}
{savedGoals.weightKg && (