feat: added index page and function

This commit is contained in:
Bart van der Braak 2023-07-20 01:55:59 +02:00
parent 62f2d4651d
commit d5889749c6
2 changed files with 31 additions and 2 deletions

13
src/lib/calculate-age.ts Normal file
View file

@ -0,0 +1,13 @@
export function calculateAge(birthdate: string): number {
const birthDate = new Date(birthdate);
const currentDate = new Date();
let age = currentDate.getFullYear() - birthDate.getFullYear();
const monthDiff = currentDate.getMonth() - birthDate.getMonth();
if (monthDiff < 0 || (monthDiff === 0 && currentDate.getDate() < birthDate.getDate())) {
age--;
}
return age;
}