<commit_before>const months = [
    'Январь', 'Февраль',
    'Март', 'Апрель', 'Май',
    'Июнь', 'Июль', 'Август',
    'Сентябрь', 'Октябрь', 'Ноябрь',
    'Декабрь'
];

class DatePicker {
    constructor(el) {
        console.log('DatePicker.constructor', el);
        this.el = el;
        this.year = null;
        this.month = null;
        this.selectedYear = null;
        this.selectedMonth = null;
        this.selectedDate = null;
        this.onDateSelected = null;
        this.el.addEventListener('click', this.onClick.bind(this));
        this.el.addEventListener('mousedown', (e) => {
            // console.log('mousedown', e);
            e.preventDefault();
            e.stopPropagation();
            return false;
        });
    }

    onClick(e) {
        // console.log('DatePicker.onClick', e);
        if (e.target === this.getNext()) {
            return this.onNext();
        } else if (e.target === this.getPrev()) {
            return this.onPrev();
        } else if (e.target.nodeName === 'TD' && e.target.classList.contains('selectable')) {
            return this.onDateClick(e.target);
        }
    }

    onDateClick(target) {
        // console.log('DatePicker.onDateClick', target.dataset);
        if (this.onDateSelected) {
            this.selectedYear = parseInt(target.dataset.year);
            this.selectedMonth = parseInt(target.dataset.month);
            this.selectedDate = parseInt(target.dataset.date);
            const date = new Date(this.selectedYear, this.selectedMonth, this.selectedDate);
            // console.log('date:', date);
            this.onDateSelected(date);
        }
    }

    onNext() {
        // console.log('DatePicker.onNext');
        if (this.year === null) throw new Error('no current year');
        if (this.month === null) throw new Error('no current month');
        const next = new Date(this.year, this.month);
        next.setMonth(next.getMonth() + 1);
        this.setYearMonth(next.getFullYear(), next.getMonth());
    }

    onPrev() {
        // console.log('DatePicker.onPrev');
        if (this.year === null) throw new Error('no current year');
        if (this.month === null) throw new Error('no current month');
        const next = new Date(this.year, this.month);
        next.setMonth(next.getMonth() - 1);
        this.setYearMonth(next.getFullYear(), next.getMonth());
    }

    getCaption() {
        return this.el.querySelector('caption > div > span');
    }

    getNext() {
        return this.el.querySelector('caption > div > a.next');
    }

    getPrev() {
        return this.el.querySelector('caption > div > a.prev');
    }

    static getDay(date) {
        let day = date.getDay() - 1;
        if (day === -1) day = 6;
        return day;
    }

    isDateSelected() {
        return this.selectedYear !== null && this.selectedMonth && this.selectedDate;
    }

    setSelectedDate(year, month, date) {
        this.selectedYear = year;
        this.selectedMonth = month;
        this.selectedDate = date;
    }

    setYearMonth(year, month) {
        console.log('DatePicker.setYearMonth', year, month);
        const now = new Date();
        const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
        if (year === undefined) year = today.getFullYear();
        if (month === undefined) month = today.getMonth();
        this.year = year;
        this.month = month;
        const date = new Date(year, month, 1); // first day of month
        let day = DatePicker.getDay(date);
        if (day === 0) {
            date.setDate(date.getDate() - 7);            // first day of table
        } else {
            date.setDate(date.getDate() - day);            // first day of table
        }

        // caption
        this.getCaption().innerText = `${months[month]}, ${year}`;

        // days
        const tds = this.el.querySelectorAll('td');
        for (let i = 0; i < 42; i++) {
            tds[i].innerText = date.getDate().toString();
            tds[i].dataset.year = date.getFullYear();
            tds[i].dataset.month = date.getMonth();
            tds[i].dataset.date = date.getDate();
            if (date.getMonth() !== month) {
                tds[i].classList.add('out');
            } else {
                tds[i].classList.remove('out');
            }
            if (date >= today) {
                tds[i].classList.add('selectable');
            } else {
                tds[i].classList.remove('selectable');
            }
            if (date.getTime() === today.getTime()) {
                tds[i].classList.add('today');
            } else {
                tds[i].classList.remove('today');
            }
            if (date.getFullYear() === this.selectedYear && date.getMonth() === this.selectedMonth && date.getDate() === this.selectedDate) {
                tds[i].classList.add('selected');
            } else {
                tds[i].classList.remove('selected');
            }
            date.setDate(date.getDate() + 1);
        }
    }
}
<commit_msg>selected date check ref<commit_after>const months = [
    'Январь', 'Февраль',
    'Март', 'Апрель', 'Май',
    'Июнь', 'Июль', 'Август',
    'Сентябрь', 'Октябрь', 'Ноябрь',
    'Декабрь'
];

class DatePicker {
    constructor(el) {
        console.log('DatePicker.constructor', el);
        this.el = el;
        this.year = null;
        this.month = null;
        this.selectedYear = null;
        this.selectedMonth = null;
        this.selectedDate = null;
        this.onDateSelected = null;
        this.minDate = null;

        // events
        this.el.addEventListener('click', this.onClick.bind(this));
        this.el.addEventListener('mousedown', (e) => {
            // console.log('mousedown', e);
            e.preventDefault();
            e.stopPropagation();
            return false;
        });
    }

    onClick(e) {
        // console.log('DatePicker.onClick', e);
        if (e.target === this.getNext()) {
            return this.onNext();
        } else if (e.target === this.getPrev()) {
            return this.onPrev();
        } else if (e.target.nodeName === 'TD' && e.target.classList.contains('selectable')) {
            return this.onDateClick(e.target);
        }
    }

    onDateClick(target) {
        // console.log('DatePicker.onDateClick', target.dataset);
        if (this.onDateSelected) {
            this.selectedYear = parseInt(target.dataset.year);
            this.selectedMonth = parseInt(target.dataset.month);
            this.selectedDate = parseInt(target.dataset.date);
            const date = new Date(this.selectedYear, this.selectedMonth, this.selectedDate);
            // console.log('date:', date);
            this.onDateSelected(date);
        }
    }

    onNext() {
        // console.log('DatePicker.onNext');
        if (this.year === null) throw new Error('no current year');
        if (this.month === null) throw new Error('no current month');
        const next = new Date(this.year, this.month);
        next.setMonth(next.getMonth() + 1);
        this.setYearMonth(next.getFullYear(), next.getMonth());
    }

    onPrev() {
        // console.log('DatePicker.onPrev');
        if (this.year === null) throw new Error('no current year');
        if (this.month === null) throw new Error('no current month');
        const next = new Date(this.year, this.month);
        next.setMonth(next.getMonth() - 1);
        this.setYearMonth(next.getFullYear(), next.getMonth());
    }

    getCaption() {
        return this.el.querySelector('caption > div > span');
    }

    getNext() {
        return this.el.querySelector('caption > div > a.next');
    }

    getPrev() {
        return this.el.querySelector('caption > div > a.prev');
    }

    static getDay(date) {
        let day = date.getDay() - 1;
        if (day === -1) day = 6;
        return day;
    }

    isDateSelected() {
        return this.selectedYear !== null && this.selectedMonth !== null && this.selectedDate !== null;
    }

    setSelectedDate(year, month, date) {
        this.selectedYear = year;
        this.selectedMonth = month;
        this.selectedDate = date;
    }

    setYearMonth(year, month) {
        console.log('DatePicker.setYearMonth', year, month);
        const now = new Date();
        const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
        const selectedDate = this.isDateSelected() ? new Date(this.selectedYear, this.selectedMonth, this.selectedDate) : null;
        if (year === undefined) year = today.getFullYear();
        if (month === undefined) month = today.getMonth();
        this.year = year;
        this.month = month;
        const date = new Date(year, month, 1); // first day of month
        let day = DatePicker.getDay(date);
        if (day === 0) {
            date.setDate(date.getDate() - 7);            // first day of table
        } else {
            date.setDate(date.getDate() - day);            // first day of table
        }

        // caption
        this.getCaption().innerText = `${months[month]}, ${year}`;

        // days
        const tds = this.el.querySelectorAll('td');
        for (let i = 0; i < 42; i++) {
            tds[i].innerText = date.getDate().toString();
            tds[i].dataset.year = date.getFullYear();
            tds[i].dataset.month = date.getMonth();
            tds[i].dataset.date = date.getDate();
            if (date.getMonth() !== month) {
                tds[i].classList.add('out');
            } else {
                tds[i].classList.remove('out');
            }
            if (date.getTime() >= today.getTime()) {
                tds[i].classList.add('selectable');
            } else {
                tds[i].classList.remove('selectable');
            }
            if (date.getTime() === today.getTime()) {
                tds[i].classList.add('today');
            } else {
                tds[i].classList.remove('today');
            }
            if (selectedDate !== null && date.getTime() === selectedDate.getTime()) {
                tds[i].classList.add('selected');
            } else {
                tds[i].classList.remove('selected');
            }
            date.setDate(date.getDate() + 1);
        }
    }

    setMinDate(year, month, date) {
        this.minDate = [year, month, date];
    }
}

{'fraction_non_alphanumeric': 0.15610180973579793, 'fraction_numerical': 0.002322655569534501, 'mean_word_length': 1.901179112857945, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 19, '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': '7136000', 'n_tokens_mistral': 3101, 'n_tokens_neox': 3088, 'n_words': 605}