Files
pihkaal-me/app/utils/birthday.ts

11 lines
377 B
TypeScript

export const BIRTHDAY_DAY = 25;
export const BIRTHDAY_MONTH = 4;
export const BIRTHDAY_YEAR = 2002;
export const getAge = (now = new Date()) => {
const hadBirthdayThisYear =
now.getMonth() > BIRTHDAY_MONTH - 1 ||
(now.getMonth() === BIRTHDAY_MONTH - 1 && now.getDate() >= BIRTHDAY_DAY);
return now.getFullYear() - BIRTHDAY_YEAR - (hadBirthdayThisYear ? 0 : 1);
};