From 2c7f3278929558e957b5568a3a0c8ab70763954a Mon Sep 17 00:00:00 2001 From: Raymonzut <40148684+Raymonzut@users.noreply.github.com> Date: Tue, 16 Jun 2020 18:48:26 +0200 Subject: [PATCH] Add me.mjs with age() --- client/public/lib/me.mjs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 client/public/lib/me.mjs diff --git a/client/public/lib/me.mjs b/client/public/lib/me.mjs new file mode 100644 index 0000000..8daaa17 --- /dev/null +++ b/client/public/lib/me.mjs @@ -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 +}