<commit_before>import PropTypes    from 'prop-types';
import classNames   from 'classnames';
import React        from 'react';
import { localize } from '_common/localize';
import { toMoment } from 'Utils/Date';

const Dialog = ({
    preClass,
    selected_time,
    end_time,
    start_time,
    onChange,
    className,
}) => {
    const start_time_moment     = start_time
        ? toMoment(start_time)
        : toMoment();
    const end_time_moment       = end_time
        ? toMoment(end_time)
        : toMoment().hour('23').minute('59').seconds('59').milliseconds('999');
    const to_compare_moment     = toMoment();
    const [ hour, minute ]      = selected_time.split(':');
    const hours    = [...Array(24).keys()].map((a)=>`0${a}`.slice(-2));
    const minutes  = [...Array(12).keys()].map((a)=>`0${a * 5}`.slice(-2));

    const selectOption = (type, current_value, prev_value, is_enabled = true) => {
        if (is_enabled && prev_value) {
            const [ prev_hour, prev_minute ] = prev_value.split(':');
            if ((type === 'h' && current_value !== prev_hour) || (type === 'm' && current_value !== prev_minute)) {
                onChange(`${type === 'h' ? current_value : prev_hour}:${type === 'm' ? current_value : prev_minute}`);
            }
        }
    };

    return (
        <div className={classNames(`${preClass}__dialog`, `${className}`)}>
            <div className={`${preClass}__selector`}>
                <div className={`${preClass}__selector--hours`}>
                    <div className={classNames(`${preClass}__selector-list-title`, 'center-text')}><strong>{localize('Hour')}</strong></div>
                    <div>
                        {hours.map((h, key) => {
                            to_compare_moment.hour(h).minute(minute);
                            const is_enabled = to_compare_moment.isBetween(start_time_moment, end_time_moment)
                                && to_compare_moment.isBetween(start_time_moment, end_time_moment, 'minute');
                            return (
                                <div
                                    className={classNames(`${preClass}__selector-list-item`,
                                        { [`${preClass}__selector-list-item--selected`]: (hour === h) },
                                        { [`${preClass}__selector-list-item--disabled`]: !is_enabled })}
                                    key={key}
                                    onClick={() => { selectOption('h', h, selected_time, is_enabled); }}
                                >
                                    {h}
                                </div>
                            );
                        })}
                    </div>
                </div>
                <div className={`${preClass}__selector--minutes`}>
                    <div className={classNames(`${preClass}__selector-list-title`, 'center-text')}><strong>{localize('Minute')}</strong></div>
                    <div>
                        {minutes.map((mm, key) => {
                            to_compare_moment.hour(hour).minute(mm);
                            const is_enabled = to_compare_moment.isBetween(start_time_moment, end_time_moment, 'minute');
                            return (
                                <div
                                    className={classNames(`${preClass}__selector-list-item`,
                                        { [`${preClass}__selector-list-item--selected`]: (minute === mm) },
                                        { [`${preClass}__selector-list-item--disabled`]: !is_enabled })}
                                    key={key}
                                    onClick={() => { selectOption('m', mm, selected_time, is_enabled); }}
                                >
                                    {mm}
                                </div>
                            );
                        })}
                    </div>
                </div>
            </div>
        </div>
    );
};

Dialog.propTypes = {
    className: PropTypes.string,
    end_time : PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string,
        PropTypes.object,
    ]),
    onChange     : PropTypes.func,
    preClass     : PropTypes.string,
    selected_time: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string,
        PropTypes.object,
    ]),
    start_time: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string,
        PropTypes.object,
    ]),
};

export default Dialog;
<commit_msg>timepicker : fix tp behaviour<commit_after>import PropTypes    from 'prop-types';
import classNames   from 'classnames';
import React        from 'react';
import { localize } from '_common/localize';
import { toMoment } from 'Utils/Date';

const Dialog = ({
    preClass,
    selected_time,
    end_time,
    start_time,
    onChange,
    className,
}) => {
    const start_time_moment     = start_time
        ? toMoment(start_time)
        : toMoment();
    const end_time_moment       = end_time
        ? toMoment(end_time)
        : toMoment().hour('23').minute('59').seconds('59').milliseconds('999');
    const to_compare_moment     = toMoment();
    const [ hour, minute ]      = selected_time.split(':');
    const hours    = [...Array(24).keys()].map((a)=>`0${a}`.slice(-2));
    const minutes  = [...Array(12).keys()].map((a)=>`0${a * 5}`.slice(-2));

    const selectOption = (type, current_value, prev_value, is_enabled = true) => {
        if (is_enabled && prev_value) {
            const [ prev_hour, prev_minute ] = prev_value.split(':');
            if ((type === 'h' && current_value !== prev_hour) || (type === 'm' && current_value !== prev_minute)) {
                onChange(`${type === 'h' ? current_value : prev_hour}:${type === 'm' ? current_value : prev_minute}`);
            }
        }
    };

    return (
        <div className={classNames(`${preClass}__dialog`, `${className}`)}>
            <div className={`${preClass}__selector`}>
                <div className={`${preClass}__selector--hours`}>
                    <div className={classNames(`${preClass}__selector-list-title`, 'center-text')}><strong>{localize('Hour')}</strong></div>
                    <div>
                        {hours.map((h, key) => {
                            // Cloning so we can change the minutes without affecting minute enable/disable.
                            const start_time_moment_clone = start_time_moment.clone().minute(0);
                            const end_time_moment_clone = end_time_moment.clone().minute(0);
                            
                            to_compare_moment.hour(h);
                            const is_enabled = to_compare_moment.isBetween(start_time_moment_clone, end_time_moment_clone)
                                && to_compare_moment.isBetween(start_time_moment_clone, end_time_moment_clone, 'minute');
                            return (
                                <div
                                    className={classNames(`${preClass}__selector-list-item`,
                                        { [`${preClass}__selector-list-item--selected`]: (hour === h) },
                                        { [`${preClass}__selector-list-item--disabled`]: !is_enabled })}
                                    key={key}
                                    onClick={() => { selectOption('h', h, selected_time, is_enabled); }}
                                >
                                    {h}
                                </div>
                            );
                        })}
                    </div>
                </div>
                <div className={`${preClass}__selector--minutes`}>
                    <div className={classNames(`${preClass}__selector-list-title`, 'center-text')}><strong>{localize('Minute')}</strong></div>
                    <div>
                        {minutes.map((mm, key) => {
                            to_compare_moment.hour(hour).minute(mm);
                            const is_enabled = to_compare_moment.isBetween(start_time_moment, end_time_moment, 'minute');
                            return (
                                <div
                                    className={classNames(`${preClass}__selector-list-item`,
                                        { [`${preClass}__selector-list-item--selected`]: (minute === mm) },
                                        { [`${preClass}__selector-list-item--disabled`]: !is_enabled })}
                                    key={key}
                                    onClick={() => { selectOption('m', mm, selected_time, is_enabled); }}
                                >
                                    {mm}
                                </div>
                            );
                        })}
                    </div>
                </div>
            </div>
        </div>
    );
};

Dialog.propTypes = {
    className: PropTypes.string,
    end_time : PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string,
        PropTypes.object,
    ]),
    onChange     : PropTypes.func,
    preClass     : PropTypes.string,
    selected_time: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string,
        PropTypes.object,
    ]),
    start_time: PropTypes.oneOfType([
        PropTypes.number,
        PropTypes.string,
        PropTypes.object,
    ]),
};

export default Dialog;

{'fraction_non_alphanumeric': 0.1379745504259123, 'fraction_numerical': 0.003996214112945631, 'mean_word_length': 1.4130931235726973, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 34, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6719400', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2452, 'n_words': 382}