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() {