summaryrefslogtreecommitdiff
path: root/node_modules/moment/src/lib/create/from-string-and-array.js
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-08-18 13:29:54 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-08-18 13:29:54 +0300
commitfd70f95224374d23157ee7c0357733102cd0df53 (patch)
treee490c12e021cedaf211b292d5d623baa32a673fc /node_modules/moment/src/lib/create/from-string-and-array.js
initialHEADmaster
Diffstat (limited to 'node_modules/moment/src/lib/create/from-string-and-array.js')
-rw-r--r--node_modules/moment/src/lib/create/from-string-and-array.js67
1 files changed, 67 insertions, 0 deletions
diff --git a/node_modules/moment/src/lib/create/from-string-and-array.js b/node_modules/moment/src/lib/create/from-string-and-array.js
new file mode 100644
index 0000000..4e64167
--- /dev/null
+++ b/node_modules/moment/src/lib/create/from-string-and-array.js
@@ -0,0 +1,67 @@
+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,
+ validFormatFound,
+ bestFormatIsValid = false,
+ configfLen = config._f.length;
+
+ if (configfLen === 0) {
+ getParsingFlags(config).invalidFormat = true;
+ config._d = new Date(NaN);
+ return;
+ }
+
+ for (i = 0; i < configfLen; i++) {
+ currentScore = 0;
+ validFormatFound = false;
+ tempConfig = copyConfig({}, config);
+ if (config._useUTC != null) {
+ tempConfig._useUTC = config._useUTC;
+ }
+ tempConfig._f = config._f[i];
+ configFromStringAndFormat(tempConfig);
+
+ if (isValid(tempConfig)) {
+ validFormatFound = true;
+ }
+
+ // 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 (!bestFormatIsValid) {
+ if (
+ scoreToBeat == null ||
+ currentScore < scoreToBeat ||
+ validFormatFound
+ ) {
+ scoreToBeat = currentScore;
+ bestMoment = tempConfig;
+ if (validFormatFound) {
+ bestFormatIsValid = true;
+ }
+ }
+ } else {
+ if (currentScore < scoreToBeat) {
+ scoreToBeat = currentScore;
+ bestMoment = tempConfig;
+ }
+ }
+ }
+
+ extend(config, bestMoment || tempConfig);
+}