<commit_before>import React from "react";
import is from "is-js";
import { FormGroup, ControlLabel } from "react-bootstrap";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import moment from "moment"; // eslint-disable-line import/no-extraneous-dependencies
import ValidationComponent from "../validation/ValidationComponent";
import "./DateInput.css";

// Please look at https://github.com/Hacker0x01/react-datepicker
export default class DateInput extends ValidationComponent {

    static propTypes = {
        /**
         * Label for the form control.
         */
        label: React.PropTypes.string,
        /**
         * code use as input field name
         */
        code: React.PropTypes.string,
        /**
         * Value of the component
         */
        value: React.PropTypes.string.isRequired,
        /**
         * onChangeEvent event for the component
         */
        onChange: React.PropTypes.func,
        /**
         * Date Format
         */
        format: React.PropTypes.string,
        /**
         * Disable input
         */
        disabled: React.PropTypes.bool,
        /**
         * it specifies that an input field is read-only
         */
        readOnly: React.PropTypes.bool,
        /**
         * it specifies that an input field is hidden or visible
         */
        hidden: React.PropTypes.bool
    };

    /**
     * defaultProps
     * @static
     */
    static defaultProps = {
        format: "DD/MM/YYYY",
        disabled: false,
        readOnly: false,
        hidden: false
    };

    static refName="innerInput";

    render(): Object {
        let selected = (is.number(this.props.value)) ? moment(this.props.value) : null;
        let label = this.props.label === undefined ? <span /> :
            <ControlLabel className="control-label">{this.props.label}</ControlLabel>;
        return (
            <FormGroup hidden={this.props.hidden} >
                {label}
                <DatePicker
                    ref={DateInput.refName}
                    className="form-control form-control-error"
                    selected={selected}
                    disabled={this.props.disabled}
                    onChange={this.__onChange}
                    name={this.props.code}
                    showYearDropdown
                    isClearable={!this.props.disabled}
                    minDate={this.props.minDate}
                    maxDate={this.props.maxDate}
                    startDate={this.props.startDate}
                    endDate={this.props.endDate}
                    showTodayButton={"Bugün"}
                    dateFormat={this.props.format}
                />
                {super.validationResult()}
            </FormGroup>);
    }

    /**
     * Internal onchange handler.
     */
    __onChange(selection: Object): boolean {
        let e = {};
        e.target = {};

        if (selection) {
            e.target.parsedValue = selection.toDate().getTime();
        } else {
            e.target.parsedValue = null;
        }
        let result = true;
        if (this.props.onChange) {
            result = !(this.props.onChange(e) === false);
        }
        return result;
    }
}
<commit_msg>don't expect only timestamp as date. if the date is invalid leave the input blank.<commit_after>import React from "react";
import is from "is-js";
import { FormGroup, ControlLabel } from "react-bootstrap";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import moment from "moment"; // eslint-disable-line import/no-extraneous-dependencies
import ValidationComponent from "../validation/ValidationComponent";
import "./DateInput.css";

// Please look at https://github.com/Hacker0x01/react-datepicker
export default class DateInput extends ValidationComponent {

    static propTypes = {
        /**
         * Label for the form control.
         */
        label: React.PropTypes.string,
        /**
         * code use as input field name
         */
        code: React.PropTypes.string,
        /**
         * Value of the component
         */
        value: React.PropTypes.string.isRequired,
        /**
         * onChangeEvent event for the component
         */
        onChange: React.PropTypes.func,
        /**
         * Date Format
         */
        format: React.PropTypes.string,
        /**
         * Disable input
         */
        disabled: React.PropTypes.bool,
        /**
         * it specifies that an input field is read-only
         */
        readOnly: React.PropTypes.bool,
        /**
         * it specifies that an input field is hidden or visible
         */
        hidden: React.PropTypes.bool
    };

    /**
     * defaultProps
     * @static
     */
    static defaultProps = {
        format: "DD/MM/YYYY",
        disabled: false,
        readOnly: false,
        hidden: false
    };

    static refName="innerInput";

    render(): Object {
        let selected = moment(this.props.value);
        let label = this.props.label === undefined ? <span /> :
            <ControlLabel className="control-label">{this.props.label}</ControlLabel>;
        return (
            <FormGroup hidden={this.props.hidden} >
                {label}
                <DatePicker
                    ref={DateInput.refName}
                    className="form-control form-control-error"
                    selected={selected.isValid() ? selected : ""}
                    disabled={this.props.disabled}
                    onChange={this.__onChange}
                    name={this.props.code}
                    showYearDropdown
                    isClearable={!this.props.disabled}
                    minDate={this.props.minDate}
                    maxDate={this.props.maxDate}
                    startDate={this.props.startDate}
                    endDate={this.props.endDate}
                    showTodayButton={"Bugün"}
                    dateFormat={this.props.format}
                />
                {super.validationResult()}
            </FormGroup>);
    }

    /**
     * Internal onchange handler.
     */
    __onChange(selection: Object): boolean {
        let e = {};
        e.target = {};

        if (selection) {
            e.target.parsedValue = selection.toDate().getTime();
        } else {
            e.target.parsedValue = null;
        }
        let result = true;
        if (this.props.onChange) {
            result = !(this.props.onChange(e) === false);
        }
        return result;
    }
}

{'fraction_non_alphanumeric': 0.11264822134387352, 'fraction_numerical': 0.0009121313469139556, 'mean_word_length': 1.58913813459268, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 2, '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': '4977765', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1663, 'n_words': 367}