<commit_before>/* eslint-disable react/no-array-index-key,jsx-a11y/click-events-have-key-events */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TransitionGroup, CSSTransition } from 'react-transition-group';

import Month from './Month';
import areDatesEqual from '../utils/areDatesEqual';


const TODAY = new Date();
const TRANSITION_TIME = 300;
const MONTH_NAMES = ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];

export default class Calendar extends Component {
    static propTypes = {
        startDate: PropTypes.instanceOf(Date).isRequired,
        endDate: PropTypes.instanceOf(Date).isRequired,
        onDateSelect: PropTypes.func.isRequired,
        selected: PropTypes.instanceOf(Date),
        activated: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
        highlighted: PropTypes.oneOfType([
            PropTypes.shape({
                dates: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
                color: PropTypes.string
            }),
            PropTypes.arrayOf(PropTypes.shape({
                dates: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
                color: PropTypes.string
            }))
        ]),
        activateAll: PropTypes.bool,
    };

    static defaultProps = {
        selected: TODAY,
        activateAll: true,
        activated: null,
        highlighted: null,
    };

    constructor() {
        super();

        this.state = {
            focus: new Date(),
            animationKey: 0.05,
            months: [],
            animation: '',
        };

        this.navigateLeftOnClick = this.navigateLeftOnClick.bind(this);
        this.navigateRightOnClick = this.navigateRightOnClick.bind(this);

        this.handleTouchStart = this.handleTouchStart.bind(this);
        this.handleTouchMove = this.handleTouchMove.bind(this);
        this.handleTouchEnd = this.handleTouchEnd.bind(this);
    }

    componentWillMount() {
        const { selected } = this.props; // TODO: SELECTED SHOULD NOT BE OUTSIDE THE START AND END TIME. ADDITIONALLY SELECTED SHOULD BE THE FIRST DATE IN TIME CONTEXT, NOT THE FIRST DATE OF THE LIST

        const active = new Date(selected.getFullYear(), selected.getMonth(), selected.getDate());
        this.setMonths(active);
    }

    setMonths(_focus) {
        const _leftHidden = new Date(_focus.getFullYear(), _focus.getMonth() - 1, 1);
        const _rightShown = new Date(_focus.getFullYear(), _focus.getMonth() + 1, 1);
        const _rightHidden = new Date(_focus.getFullYear(), _focus.getMonth() + 2, 1);

        this.setState({
            focus: _focus,
            months: [
                {
                    title: MONTH_NAMES[_leftHidden.getMonth()],
                    className: 'left__hidden month',
                    startDate: _leftHidden,
                    endDate: new Date(_leftHidden.getFullYear(), _leftHidden.getMonth() + 1, 0)
                },
                {
                    title: MONTH_NAMES[_focus.getMonth()],
                    className: 'left__shown month',
                    startDate: new Date(_focus.getFullYear(), _focus.getMonth(), 1),
                    endDate: new Date(_focus.getFullYear(), _focus.getMonth() + 1, 0)
                },
                {
                    title: MONTH_NAMES[_rightShown.getMonth()],
                    className: 'right__shown month',
                    startDate: _rightShown,
                    endDate: new Date(_rightShown.getFullYear(), _rightShown.getMonth() + 1, 0)
                },
                {
                    title: MONTH_NAMES[_rightHidden.getMonth()],
                    className: 'right__hidden month',
                    startDate: _rightHidden,
                    endDate: new Date(_rightHidden.getFullYear(), _rightHidden.getMonth() + 1, 0)
                }]
        });
    }

    getNavigateLeft() {
        const { activateAll, startDate } = this.props;
        const { focus } = this.state;

        if (!startDate) {
            return !!activateAll;
        }

        if (startDate.getFullYear() < focus.getFullYear()) {
            return true;
        }

        if (startDate.getFullYear() === focus.getFullYear()
            && startDate.getMonth() < focus.getMonth()) {
            return true;
        }

        return false;
    }
<commit_msg>Add translation to months<commit_after>/* eslint-disable react/no-array-index-key,jsx-a11y/click-events-have-key-events */
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { TransitionGroup, CSSTransition } from 'react-transition-group';

import Month from './Month';
import areDatesEqual from '../utils/areDatesEqual';


const TODAY = new Date();
const TRANSITION_TIME = 300;
const MONTH_NAMES = {
    de: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
    en: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
};

function getMonthNames(language = chayns.env.language) {
    return MONTH_NAMES[language] || MONTH_NAMES.de;
}

export default class Calendar extends Component {
    static propTypes = {
        startDate: PropTypes.instanceOf(Date).isRequired,
        endDate: PropTypes.instanceOf(Date).isRequired,
        onDateSelect: PropTypes.func.isRequired,
        selected: PropTypes.instanceOf(Date),
        activated: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
        highlighted: PropTypes.oneOfType([
            PropTypes.shape({
                dates: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
                color: PropTypes.string
            }),
            PropTypes.arrayOf(PropTypes.shape({
                dates: PropTypes.arrayOf(PropTypes.instanceOf(Date)),
                color: PropTypes.string
            }))
        ]),
        activateAll: PropTypes.bool,
    };

    static defaultProps = {
        selected: TODAY,
        activateAll: true,
        activated: null,
        highlighted: null,
    };

    constructor() {
        super();

        this.state = {
            focus: new Date(),
            animationKey: 0.05,
            months: [],
            animation: '',
        };

        this.navigateLeftOnClick = this.navigateLeftOnClick.bind(this);
        this.navigateRightOnClick = this.navigateRightOnClick.bind(this);

        this.handleTouchStart = this.handleTouchStart.bind(this);
        this.handleTouchMove = this.handleTouchMove.bind(this);
        this.handleTouchEnd = this.handleTouchEnd.bind(this);
    }

    componentWillMount() {
        const { selected } = this.props; // TODO: SELECTED SHOULD NOT BE OUTSIDE THE START AND END TIME. ADDITIONALLY SELECTED SHOULD BE THE FIRST DATE IN TIME CONTEXT, NOT THE FIRST DATE OF THE LIST

        const active = new Date(selected.getFullYear(), selected.getMonth(), selected.getDate());
        this.setMonths(active);
    }

    setMonths(_focus) {
        const _leftHidden = new Date(_focus.getFullYear(), _focus.getMonth() - 1, 1);
        const _rightShown = new Date(_focus.getFullYear(), _focus.getMonth() + 1, 1);
        const _rightHidden = new Date(_focus.getFullYear(), _focus.getMonth() + 2, 1);

        const monthNames = getMonthNames();

        this.setState({
            focus: _focus,
            months: [
                {
                    title: monthNames[_leftHidden.getMonth()],
                    className: 'left__hidden month',
                    startDate: _leftHidden,
                    endDate: new Date(_leftHidden.getFullYear(), _leftHidden.getMonth() + 1, 0)
                },
                {
                    title: monthNames[_focus.getMonth()],
                    className: 'left__shown month',
                    startDate: new Date(_focus.getFullYear(), _focus.getMonth(), 1),
                    endDate: new Date(_focus.getFullYear(), _focus.getMonth() + 1, 0)
                },
                {
                    title: monthNames[_rightShown.getMonth()],
                    className: 'right__shown month',
                    startDate: _rightShown,
                    endDate: new Date(_rightShown.getFullYear(), _rightShown.getMonth() + 1, 0)
                },
                {
                    title: monthNames[_rightHidden.getMonth()],
                    className: 'right__hidden month',
                    startDate: _rightHidden,
                    endDate: new Date(_rightHidden.getFullYear(), _rightHidden.getMonth() + 1, 0)
                }]
        });
    }

    getNavigateLeft() {
        const { activateAll, startDate } = this.props;
        const { focus } = this.state;

        if (!startDate) {
            return !!activateAll;
        }

        if (startDate.getFullYear() < focus.getFullYear()) {
            return true;
        }

        if (startDate.getFullYear() === focus.getFullYear()
            && startDate.getMonth() < focus.getMonth()) {
            return true;
        }

        return false;
    }

{'fraction_non_alphanumeric': 0.11892247043363995, 'fraction_numerical': 0.005037231712658782, 'mean_word_length': 2.045348449483161, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '6980043', 'n_tokens_mistral': 2636, 'n_tokens_neox': 2468, 'n_words': 534}