This commit is contained in:
AdisakKanthawilang 2024-07-01 17:27:01 +07:00
parent 54a743532b
commit 928d806313

View file

@ -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 };
}