Sha256: 28f59ff8b83cf780adaa901f198229135b2c79c7cab96b0022ccf8d841a67ffc

Contents?: true

Size: 1.43 KB

Versions: 58

Compression:

Stored size: 1.43 KB

Contents

import { copyConfig } from '../moment/constructor';
import { configFromStringAndFormat } from './from-string-and-format';
import getParsingFlags from './parsing-flags';
import { isValid } from './valid';
import extend from '../utils/extend';

// date from string and array of format strings
export function configFromStringAndArray(config) {
    var tempConfig,
        bestMoment,

        scoreToBeat,
        i,
        currentScore;

    if (config._f.length === 0) {
        getParsingFlags(config).invalidFormat = true;
        config._d = new Date(NaN);
        return;
    }

    for (i = 0; i < config._f.length; i++) {
        currentScore = 0;
        tempConfig = copyConfig({}, config);
        if (config._useUTC != null) {
            tempConfig._useUTC = config._useUTC;
        }
        tempConfig._f = config._f[i];
        configFromStringAndFormat(tempConfig);

        if (!isValid(tempConfig)) {
            continue;
        }

        // if there is any input that was not parsed add a penalty for that format
        currentScore += getParsingFlags(tempConfig).charsLeftOver;

        //or tokens
        currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;

        getParsingFlags(tempConfig).score = currentScore;

        if (scoreToBeat == null || currentScore < scoreToBeat) {
            scoreToBeat = currentScore;
            bestMoment = tempConfig;
        }
    }

    extend(config, bestMoment || tempConfig);
}

Version data entries

58 entries across 57 versions & 12 rubygems

Version Path
active_record_survey_api-0.0.19 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
active_record_survey_api-0.0.18 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
active_record_survey_api-0.0.17 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
active_record_survey_api-0.0.14 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.9 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
active_record_survey_api-0.0.12 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
locomotivecms-3.2.0.rc1 vendor/assets/components/locomotive_sources/moment/src/lib/create/from-string-and-array.js
locomotivecms-3.1.1 vendor/assets/components/locomotive_sources/moment/src/lib/create/from-string-and-array.js
locomotivecms-3.1.0 vendor/assets/components/locomotive_sources/moment/src/lib/create/from-string-and-array.js
active_record_survey_api-0.0.11 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
locomotivecms-3.1.0.rc3 vendor/assets/components/locomotive_sources/moment/src/lib/create/from-string-and-array.js
locomotivecms-3.1.0.rc2 vendor/assets/components/locomotive_sources/moment/src/lib/create/from-string-and-array.js
locomotivecms-3.1.0.rc1 vendor/assets/components/locomotive_sources/moment/src/lib/create/from-string-and-array.js
active_record_survey_api-0.0.7 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
active_record_survey_api-0.0.6 spec/test_app/vendor/assets/bower_components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.8 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.7 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
sedge_cms-0.0.1 vendor/assets/components/moment/src/lib/create/from-string-and-array.js