mirror of
https://github.com/bartvdbraak/hellob.art.git
synced 2025-06-28 23:39:11 +00:00
feat: added index page and function
This commit is contained in:
parent
62f2d4651d
commit
d5889749c6
2 changed files with 31 additions and 2 deletions
13
src/lib/calculate-age.ts
Normal file
13
src/lib/calculate-age.ts
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue