Sha256: 027b00e5abb6849b46f8ade9a60c29191446aafe6c08ec78e8cb848c9c21da41

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

import { copyConfig } from '../moment/constructor';
import { configFromStringAndFormat } from './from-string-and-format';
import defaultParsingFlags from './default-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) {
        config._pf.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._pf = defaultParsingFlags();
        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 += tempConfig._pf.charsLeftOver;

        //or tokens
        currentScore += tempConfig._pf.unusedTokens.length * 10;

        tempConfig._pf.score = currentScore;

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

    extend(config, bestMoment || tempConfig);
}

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
date_picker-0.0.6 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.5 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.4 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.3 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.2 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
date_picker-0.0.1 test/dummy/vendor/assets/components/moment/src/lib/create/from-string-and-array.js
puppet-herald-0.8.1 lib/puppet-herald/public/bower_components/moment/src/lib/create/from-string-and-array.js
puppet-herald-0.8.0 lib/puppet-herald/public/bower_components/moment/src/lib/create/from-string-and-array.js