From 6b92b2020d853cfca5848a92e9d7886dd897432c Mon Sep 17 00:00:00 2001 From: boi12321 Date: Sat, 27 May 2023 17:46:31 +0200 Subject: [PATCH] refactor age check --- src/actors.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/actors.js b/src/actors.js index 7af1d6fe..71cbf38e 100755 --- a/src/actors.js +++ b/src/actors.js @@ -33,6 +33,7 @@ const capitalize = require('./utils/capitalize'); const resolvePlace = require('./utils/resolve-place'); const { resolveLayoutScraper } = require('./scrapers/resolve'); const getRecursiveParameters = require('./utils/get-recursive-parameters'); +const dayjs = require('dayjs'); const hairColors = { 'jet-black': 'black', @@ -334,6 +335,13 @@ function curateProfileEntry(profile) { return curatedProfileEntry; } +/** + * @param {Date} birthDate + */ +function isAdult(birthDate) { + return dayjs(birthDate).diff(new Date(), "years") >= 18; +} + async function curateProfile(profile, actor) { if (!profile) { return null; @@ -375,7 +383,7 @@ async function curateProfile(profile, actor) { const dateOfBirth = profile.dateOfBirth || profile.birthdate; curatedProfile.dateOfBirth = (!Number.isNaN(Number(dateOfBirth)) // possibly valid date - && new Date() - dateOfBirth > 567648000000 // over 18 + && isAdult(dateOfBirth) // over 18 && dateOfBirth) || null;