From d5889749c69f7ce808154676a423786c92c860c4 Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Thu, 20 Jul 2023 01:55:59 +0200 Subject: [PATCH] feat: added index page and function --- src/lib/calculate-age.ts | 13 +++++++++++++ src/routes/+page.svelte | 20 ++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/lib/calculate-age.ts diff --git a/src/lib/calculate-age.ts b/src/lib/calculate-age.ts new file mode 100644 index 0000000..0916c0d --- /dev/null +++ b/src/lib/calculate-age.ts @@ -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; +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 5982b0a..3589c75 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,2 +1,18 @@ -

Welcome to SvelteKit

-

Visit kit.svelte.dev to read the documentation

+ + + +
+

Hello, I'm Bart van der Braak!

+

I'm {age} years old and have been with my girlfriend for {girlfriendDuration} years.

+

I'm located in {location}.

+

I love {loves}.

+

I'm passionate about {passion}.

+
\ No newline at end of file