From 928d806313960a93349a0c21ed0f03979ef0b994 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 1 Jul 2024 17:27:01 +0700 Subject: [PATCH] fix --- src/interfaces/utils.ts | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index c8270771..56424ff6 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -5,17 +5,28 @@ export function calculateAge(start: Date, end = new Date()) { let month = end.getMonth() - start.getMonth(); let day = end.getDate() - start.getDate(); - if (month < 0) { - month += 12; - year -= 1; - } - if (day < 0) { - month -= 1; - day = - new Date(start.getFullYear(), start.getMonth(), 0).getDate() - - start.getDate() + - end.getDate(); - } + // if (month < 0) { + // month += 12; + // year -= 1; + // } + // if (day < 0) { + // month -= 1; + // day = + // new Date(start.getFullYear(), start.getMonth(), 0).getDate() - + // start.getDate() + + // end.getDate(); + // } + + if (day < 0) { + month -= 1; + day += new Date(end.getFullYear(), end.getMonth(), 0).getDate(); + } + + if (month < 0) { + month += 12; + year -= 1; + } + return { year, month, day }; }