fix(main): fix age calculation
This commit is contained in:
parent
c4549b8a95
commit
b5dcbb60d4
1 changed files with 12 additions and 9 deletions
|
@ -11,16 +11,20 @@
|
||||||
import Mastodon from "@inqling/svelte-icons/simple-icons/mastodon.svelte"
|
import Mastodon from "@inqling/svelte-icons/simple-icons/mastodon.svelte"
|
||||||
import YouTube from "@inqling/svelte-icons/simple-icons/youtube.svelte"
|
import YouTube from "@inqling/svelte-icons/simple-icons/youtube.svelte"
|
||||||
|
|
||||||
const today = new Date()
|
function myAge() {
|
||||||
const birthDay = new Date(2002, 7, 30)
|
const now = new Date()
|
||||||
|
const birth = new Date("2002-07-30") // my birthday :D
|
||||||
|
|
||||||
const month = today.getMonth() + 1
|
const age = now.getFullYear() - birth.getFullYear()
|
||||||
const birthMonth = birthDay.getMonth() + 1
|
|
||||||
|
|
||||||
let age = today.getFullYear() - birthDay.getFullYear()
|
let month = now.getMonth()
|
||||||
|
let birthMonth = birth.getMonth()
|
||||||
|
|
||||||
if (birthMonth > month || (birthMonth === month && birthDay.getDate() >= today.getDate())) {
|
if (birthMonth > month || (birthMonth === month && birth.getDate() >= now.getDate())) {
|
||||||
age--
|
return age - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
return age
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -40,8 +44,7 @@
|
||||||
<h2>Who am I?</h2>
|
<h2>Who am I?</h2>
|
||||||
|
|
||||||
<span>
|
<span>
|
||||||
I am a <b>{new Date().getFullYear() - 2002} years old</b> college student studying computer science
|
I am a <b>{myAge()} years old</b> college student studying computer science in Seoul, South Korea.
|
||||||
in Seoul, South Korea.
|
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<h2>Contact</h2>
|
<h2>Contact</h2>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue