<commit_before>const $ = require('jquery');

/**
 * Utility script to enable toggling visibility of pre registration for voting 
 * based on birthdate on '/profile/about' form
 */

function togglePreregistrationPrompt(event) {
    const birthdate = event.target.value;
    const preRegisteredContent = document.getElementById('voter-reg-cta-pre-registration');

    const calculateAge = (date) => {
        const now = new Date();
        return now.getFullYear() - date.getFullYear();
    }

    if(birthdate.length === 10 && new Date(birthdate)) {
        const newBirthdate = new Date(birthdate);
        const age = calculateAge(newBirthdate);

        if(16 <= age && age < 18) {
            preRegisteredContent.classList.remove('hidden');
        }<commit_msg>fixes bug in the age checker (#1040)<commit_after>const $ = require('jquery');

/**
 * Utility script to enable toggling visibility of pre registration for voting 
 * based on birthdate on '/profile/about' form
 */

function togglePreregistrationPrompt(event) {
    const birthdate = event.target.value;
    const preRegisteredContent = document.getElementById('voter-reg-cta-pre-registration');

    const calculateAge = (date) => {
        const now = new Date();
        let age = now.getFullYear() - date.getFullYear();
        const m = now.getMonth() - date.getMonth();
        if (m < 0 || (m === 0 && now.getDate() < date.getDate())) {
            age--;
        }
        return age;
    }

    if(birthdate.length === 10 && new Date(birthdate)) {
        const newBirthdate = new Date(birthdate);
        const age = calculateAge(newBirthdate);

        if(16 <= age && age < 18) {
            preRegisteredContent.classList.remove('hidden');
        }
{'fraction_non_alphanumeric': 0.12955465587044535, 'fraction_numerical': 0.010410641989589358, 'mean_word_length': 2.8530066815144766, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7318855', 'n_tokens_mistral': 520, 'n_tokens_neox': 482, 'n_words': 127}