<commit_before>import classNames               from 'classnames';
import {
    PropTypes as MobxPropTypes,
    observer }                  from 'mobx-react';
import moment                   from 'moment';
import PropTypes                from 'prop-types';
import React                    from 'react';
import { localize }             from '_common/localize';
import Datepicker               from 'App/Components/Form/DatePicker';
import Dropdown                 from 'App/Components/Form/dropdown.jsx';
import Fieldset                 from 'App/Components/Form/fieldset.jsx';
import InputField               from 'App/Components/Form/input_field.jsx';
import TimePicker               from 'App/Components/Form/time_picker.jsx';
import { convertDurationUnit }  from 'Stores/Modules/Trading/Helpers/duration';

/* TODO:
      1. disable days other than today and tomorrow if start date is forward starting
*/

const expiry_list = [
    { text: localize('Duration'), value: 'duration' },
];

let now_date,
    min_date_duration,
    max_date_duration,
    min_date_expiry,
    min_day,
    max_day,
    start_date_time;

const Duration = ({
    contract_expiry_type,
    duration,
    duration_unit,
    duration_units_list,
    duration_min_max,
    expiry_date,
    expiry_time,
    expiry_type,
    onChange,
    is_minimized,
    is_nativepicker,
    server_time,
    sessions,
    start_date,
    start_time,
    validation_errors,
}) => {
    const moment_now  = moment(server_time);
    const new_min_day = convertDurationUnit(duration_min_max[contract_expiry_type].min, 's', 'd');
    const new_max_day = convertDurationUnit(duration_min_max[contract_expiry_type].max, 's', 'd');
    if (!now_date || moment_now.date() !== now_date.date() || (duration_unit === 'd' && (min_day !== new_min_day || max_day !== new_max_day))) {
        if (duration_unit === 'd') {
            min_day = new_min_day;
            max_day = new_max_day;
        }

        const moment_today = moment_now.clone().startOf('day');

        now_date          = moment_now.clone();
        min_date_duration = moment_today.clone().add(min_day || 1, 'd');
        max_date_duration = moment_today.clone().add(max_day || 365, 'd');
        min_date_expiry   = moment_today.clone();
    }
    const moment_expiry = moment.utc(expiry_date);
    const is_same_day   = moment_expiry.isSame(moment(start_date * 1000 || undefined).utc(), 'day');
    if (is_same_day) {
        const date_time = moment.utc(start_date * 1000 || undefined);
        if (start_date) {
            const [ hour, minute ] = start_time.split(':');
            date_time.hour(hour).minute(minute).second(0).add(5, 'minutes');<commit_msg>Catch Duration min-max error<commit_after>import classNames               from 'classnames';
import {
    PropTypes as MobxPropTypes,
    observer }                  from 'mobx-react';
import moment                   from 'moment';
import PropTypes                from 'prop-types';
import React                    from 'react';
import { localize }             from '_common/localize';
import Datepicker               from 'App/Components/Form/DatePicker';
import Dropdown                 from 'App/Components/Form/dropdown.jsx';
import Fieldset                 from 'App/Components/Form/fieldset.jsx';
import InputField               from 'App/Components/Form/input_field.jsx';
import TimePicker               from 'App/Components/Form/time_picker.jsx';
import { convertDurationUnit }  from 'Stores/Modules/Trading/Helpers/duration';

/* TODO:
      1. disable days other than today and tomorrow if start date is forward starting
*/

const expiry_list = [
    { text: localize('Duration'), value: 'duration' },
];

let now_date,
    min_date_duration,
    max_date_duration,
    min_date_expiry,
    min_day,
    max_day,
    start_date_time;

const Duration = ({
    contract_expiry_type,
    duration,
    duration_unit,
    duration_units_list,
    duration_min_max,
    expiry_date,
    expiry_time,
    expiry_type,
    onChange,
    is_minimized,
    is_nativepicker,
    server_time,
    sessions,
    start_date,
    start_time,
    validation_errors,
}) => {
    if (duration_min_max[contract_expiry_type]) {
        const moment_now  = moment(server_time);
        const new_min_day = convertDurationUnit(duration_min_max[contract_expiry_type].min, 's', 'd');
        const new_max_day = convertDurationUnit(duration_min_max[contract_expiry_type].max, 's', 'd');
        if (!now_date || moment_now.date() !== now_date.date() || (duration_unit === 'd' && (min_day !== new_min_day || max_day !== new_max_day))) {
            if (duration_unit === 'd') {
                min_day = new_min_day;
                max_day = new_max_day;
            }

            const moment_today = moment_now.clone().startOf('day');

            now_date          = moment_now.clone();
            min_date_duration = moment_today.clone().add(min_day || 1, 'd');
            max_date_duration = moment_today.clone().add(max_day || 365, 'd');
            min_date_expiry   = moment_today.clone();
        }
    }

    const moment_expiry = moment.utc(expiry_date);
    const is_same_day   = moment_expiry.isSame(moment(start_date * 1000 || undefined).utc(), 'day');
    if (is_same_day) {
        const date_time = moment.utc(start_date * 1000 || undefined);
        if (start_date) {
            const [ hour, minute ] = start_time.split(':');
            date_time.hour(hour).minute(minute).second(0).add(5, 'minutes');
{'fraction_non_alphanumeric': 0.11517467248908297, 'fraction_numerical': 0.0054585152838427945, 'mean_word_length': 2.6355820105820107, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5631469', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1679, 'n_words': 338}