Brought in another asset for Ray's eye form: moment
[openemr.git] / public / assets / moment-2-13-0 / src / lib / create / from-string-and-array.js
blob1d8a7a806cda2fee37170e4b5615b7acabb555e2
1 import { copyConfig } from '../moment/constructor';
2 import { configFromStringAndFormat } from './from-string-and-format';
3 import getParsingFlags from './parsing-flags';
4 import { isValid } from './valid';
5 import extend from '../utils/extend';
7 // date from string and array of format strings
8 export function configFromStringAndArray(config) {
9     var tempConfig,
10         bestMoment,
12         scoreToBeat,
13         i,
14         currentScore;
16     if (config._f.length === 0) {
17         getParsingFlags(config).invalidFormat = true;
18         config._d = new Date(NaN);
19         return;
20     }
22     for (i = 0; i < config._f.length; i++) {
23         currentScore = 0;
24         tempConfig = copyConfig({}, config);
25         if (config._useUTC != null) {
26             tempConfig._useUTC = config._useUTC;
27         }
28         tempConfig._f = config._f[i];
29         configFromStringAndFormat(tempConfig);
31         if (!isValid(tempConfig)) {
32             continue;
33         }
35         // if there is any input that was not parsed add a penalty for that format
36         currentScore += getParsingFlags(tempConfig).charsLeftOver;
38         //or tokens
39         currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10;
41         getParsingFlags(tempConfig).score = currentScore;
43         if (scoreToBeat == null || currentScore < scoreToBeat) {
44             scoreToBeat = currentScore;
45             bestMoment = tempConfig;
46         }
47     }
49     extend(config, bestMoment || tempConfig);