From b5dcbb60d4aee7c72f5ec39768b98a69d6360774 Mon Sep 17 00:00:00 2001 From: developomp Date: Sun, 2 Jul 2023 09:54:13 +0900 Subject: [PATCH] fix(main): fix age calculation --- apps/main/src/routes/+page.svelte | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/apps/main/src/routes/+page.svelte b/apps/main/src/routes/+page.svelte index c003fb6..3da589d 100644 --- a/apps/main/src/routes/+page.svelte +++ b/apps/main/src/routes/+page.svelte @@ -11,16 +11,20 @@ import Mastodon from "@inqling/svelte-icons/simple-icons/mastodon.svelte" import YouTube from "@inqling/svelte-icons/simple-icons/youtube.svelte" - const today = new Date() - const birthDay = new Date(2002, 7, 30) + function myAge() { + const now = new Date() + const birth = new Date("2002-07-30") // my birthday :D - const month = today.getMonth() + 1 - const birthMonth = birthDay.getMonth() + 1 + const age = now.getFullYear() - birth.getFullYear() - let age = today.getFullYear() - birthDay.getFullYear() + let month = now.getMonth() + let birthMonth = birth.getMonth() - if (birthMonth > month || (birthMonth === month && birthDay.getDate() >= today.getDate())) { - age-- + if (birthMonth > month || (birthMonth === month && birth.getDate() >= now.getDate())) { + return age - 1 + } + + return age } @@ -40,8 +44,7 @@

Who am I?

- I am a {new Date().getFullYear() - 2002} years old college student studying computer science - in Seoul, South Korea. + I am a {myAge()} years old college student studying computer science in Seoul, South Korea.

Contact