Add me.mjs with age()

This commit is contained in:
Raymonzut
2020-06-16 18:48:26 +02:00
parent 7506909670
commit 2c7f327892
+17
View File
@@ -0,0 +1,17 @@
export function age() {
let birthdate = new Date(2002, 8, 29)
let now = new Date()
let age = now.getFullYear() - birthdate.getFullYear()
if (now.getMonth() < birthdate.getMonth()) {
age--
}
if (
birthdate.getMonth() === now.getMonth() &&
now.getDate() < birthdate.getDate()
) {
age--
}
return age
}