<commit_before>const objectNotEmpty  = require('../../base/utility').objectNotEmpty;
const localize        = require('../../base/localize').localize;
const getLanguage     = require('../../base/language').getLanguage;
const Client          = require('../../base/client').Client;
const format_currency = require('../../common_functions/currency_to_symbol').format_currency;
const japanese_client = require('../../common_functions/country_base').japanese_client;
const MBDefaults      = require('./mb_defaults').MBDefaults;
const MBSymbols       = require('./mb_symbols').MBSymbols;
const moment          = require('moment');
const elementInnerHtml = require('../../common_functions/common_functions').elementInnerHtml;

/*
 * Contract object mocks the trading form we have on our website
 * It parses the contracts json we get from socket.send({contracts_for: 'R_50'})
 */
const MBContract = (function() {
    'use strict';

    let contracts_for_response,
        contract_timeout;

    const getContracts = function(underlying) {
        const req = {
            contracts_for: (underlying || MBDefaults.get('underlying')),
            currency     : getCurrency(),
            product_type : 'multi_barrier',
        };
        if (!underlying) {
            req.passthrough = { action: 'no-proposal' };
        }
        BinarySocket.send(req);
        if (contract_timeout) clearContractTimeout(contract_timeout);
        contract_timeout = setTimeout(getContracts, 15000);
    };

    const clearContractTimeout = function(timoutID) {
        if (timoutID) {
            clearTimeout(timoutID);
        } else {
            clearTimeout(contract_timeout);
            clearTimeout(remainingTimeout);
        }
    };

    const durationText = function(dur) {
        const durationMap = {
            m: 'min',
            h: 'h',
            d: 'day',
            W: 'week',
            M: 'month',
            Y: 'year',
        };
        Object.keys(durationMap).forEach(function(key) {
            dur = dur.replace(key, localize(durationMap[key] + (+dur[0] === 1 || /h/.test(key) ? '' : 's')));
        });
        return dur;
    };

    const PeriodText = function(trading_period) {
        let date_expiry,
            duration;
        if (typeof trading_period === 'object') {
            date_expiry = trading_period.date_expiry.epoch;
            duration = trading_period.duration;
        } else {
            date_expiry = trading_period.split('_')[1];
            duration = trading_period.split('_')[2];
        }
        const text_value = moment().utc(date_expiry * 1000)
                            .utcOffset(japanese_client() ? '+09:00' : '+00:00')
                            .locale(getLanguage().toLowerCase())
                            .format('MMM Do, HH:mm')
                            .replace(/08:59/, '09:00«') + ' (' + durationText(duration.replace('0d', '1d')) + ')';
        return text_value.toString();
    };<commit_msg>Fix period text<commit_after>const objectNotEmpty  = require('../../base/utility').objectNotEmpty;
const localize        = require('../../base/localize').localize;
const getLanguage     = require('../../base/language').getLanguage;
const Client          = require('../../base/client').Client;
const format_currency = require('../../common_functions/currency_to_symbol').format_currency;
const japanese_client = require('../../common_functions/country_base').japanese_client;
const MBDefaults      = require('./mb_defaults').MBDefaults;
const MBSymbols       = require('./mb_symbols').MBSymbols;
const moment          = require('moment');
const elementInnerHtml = require('../../common_functions/common_functions').elementInnerHtml;

/*
 * Contract object mocks the trading form we have on our website
 * It parses the contracts json we get from socket.send({contracts_for: 'R_50'})
 */
const MBContract = (function() {
    'use strict';

    let contracts_for_response,
        contract_timeout;

    const getContracts = function(underlying) {
        const req = {
            contracts_for: (underlying || MBDefaults.get('underlying')),
            currency     : getCurrency(),
            product_type : 'multi_barrier',
        };
        if (!underlying) {
            req.passthrough = { action: 'no-proposal' };
        }
        BinarySocket.send(req);
        if (contract_timeout) clearContractTimeout(contract_timeout);
        contract_timeout = setTimeout(getContracts, 15000);
    };

    const clearContractTimeout = function(timoutID) {
        if (timoutID) {
            clearTimeout(timoutID);
        } else {
            clearTimeout(contract_timeout);
            clearTimeout(remainingTimeout);
        }
    };

    const durationText = function(dur) {
        const durationMap = {
            m: 'min',
            h: 'h',
            d: 'day',
            W: 'week',
            M: 'month',
            Y: 'year',
        };
        Object.keys(durationMap).forEach(function(key) {
            dur = dur.replace(key, localize(durationMap[key] + (+dur[0] === 1 || /h/.test(key) ? '' : 's')));
        });
        return dur;
    };

    const PeriodText = function(trading_period) {
        let date_expiry,
            duration;
        if (typeof trading_period === 'object') {
            date_expiry = trading_period.date_expiry.epoch;
            duration = trading_period.duration;
        } else {
            date_expiry = trading_period.split('_')[1];
            duration = trading_period.split('_')[2];
        }
        const text_value = moment.utc(date_expiry * 1000)
                            .utcOffset(japanese_client() ? '+09:00' : '+00:00')
                            .locale(getLanguage().toLowerCase())
                            .format('MMM Do, HH:mm')
                            .replace(/08:59/, '09:00«') + ' (' + durationText(duration.replace('0d', '1d')) + ')';
        return text_value.toString();
    };
{'fraction_non_alphanumeric': 0.14155712841253792, 'fraction_numerical': 0.011122345803842264, 'mean_word_length': 2.1891456206340676, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1563135', 'n_tokens_mistral': 1703, 'n_tokens_neox': 1644, 'n_words': 314}