(config)
| 2847 | |
| 2848 | // date from string and array of format strings |
| 2849 | function configFromStringAndArray(config) { |
| 2850 | var tempConfig, |
| 2851 | bestMoment, |
| 2852 | scoreToBeat, |
| 2853 | i, |
| 2854 | currentScore, |
| 2855 | validFormatFound, |
| 2856 | bestFormatIsValid = false; |
| 2857 | |
| 2858 | if (config._f.length === 0) { |
| 2859 | getParsingFlags(config).invalidFormat = true; |
| 2860 | config._d = new Date(NaN); |
| 2861 | return; |
| 2862 | } |
| 2863 | |
| 2864 | for (i = 0; i < config._f.length; i++) { |
| 2865 | currentScore = 0; |
| 2866 | validFormatFound = false; |
| 2867 | tempConfig = copyConfig({}, config); |
| 2868 | if (config._useUTC != null) { |
| 2869 | tempConfig._useUTC = config._useUTC; |
| 2870 | } |
| 2871 | tempConfig._f = config._f[i]; |
| 2872 | configFromStringAndFormat(tempConfig); |
| 2873 | |
| 2874 | if (isValid(tempConfig)) { |
| 2875 | validFormatFound = true; |
| 2876 | } |
| 2877 | |
| 2878 | // if there is any input that was not parsed add a penalty for that format |
| 2879 | currentScore += getParsingFlags(tempConfig).charsLeftOver; |
| 2880 | |
| 2881 | //or tokens |
| 2882 | currentScore += getParsingFlags(tempConfig).unusedTokens.length * 10; |
| 2883 | |
| 2884 | getParsingFlags(tempConfig).score = currentScore; |
| 2885 | |
| 2886 | if (!bestFormatIsValid) { |
| 2887 | if ( |
| 2888 | scoreToBeat == null || |
| 2889 | currentScore < scoreToBeat || |
| 2890 | validFormatFound |
| 2891 | ) { |
| 2892 | scoreToBeat = currentScore; |
| 2893 | bestMoment = tempConfig; |
| 2894 | if (validFormatFound) { |
| 2895 | bestFormatIsValid = true; |
| 2896 | } |
| 2897 | } |
| 2898 | } else { |
| 2899 | if (currentScore < scoreToBeat) { |
| 2900 | scoreToBeat = currentScore; |
| 2901 | bestMoment = tempConfig; |
| 2902 | } |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | extend(config, bestMoment || tempConfig); |
no test coverage detected