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
card-1.100.0 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.99.6 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.99.5 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.99.4 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.99.3 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.99.2 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
ilog-0.4.1 node_modules/moment/src/lib/create/from-string-and-array.js
ilog-0.4.0 node_modules/moment/src/lib/create/from-string-and-array.js
ilog-0.3.3 node_modules/moment/src/lib/create/from-string-and-array.js
card-1.99.1 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.99.0 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
jester-data-8.0.0 node_modules/moment/src/lib/create/from-string-and-array.js
ezii-os-5.2.1 node_modules/moment/src/lib/create/from-string-and-array.js
ezii-os-2.0.1 node_modules/moment/src/lib/create/from-string-and-array.js
card-1.98.3 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.98.2 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.98.1 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.98.0 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.97.0.1 mod/date/vendor/moment/src/lib/create/from-string-and-array.js
card-1.97.0 mod/date/vendor/moment/src/lib/create/from-string-and-array.js