]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
Fixing string+formats parsing with new iterative parser
authorTim Wood <washwithcare@gmail.com>
Wed, 11 Apr 2012 03:13:03 +0000 (20:13 -0700)
committerTim Wood <washwithcare@gmail.com>
Wed, 11 Apr 2012 03:13:03 +0000 (20:13 -0700)
moment.js

index ec30728ed87303a179911a7fa7f29ec74cd7d063..cd489fc7a7a8e2529ea66a67dbeb5ac7b758b9fd 100644 (file)
--- a/moment.js
+++ b/moment.js
     // date from string and array of format strings
     function makeDateFromStringAndArray(string, formats) {
         var output,
-            scores = [],
             inputParts = string.match(parseMultipleFormatChunker),
+            formattedInputParts,
             scoreToBeat = 99,
             i,
-            curDate,
-            curScore;
+            currentDate,
+            currentScore;
         for (i = 0; i < formats.length; i++) {
-            curDate = makeDateFromStringAndFormat(string, formats[i]);
-            curScore = compareArrays(inputParts, formatMoment(new Moment(curDate), formats[i]).match(inputCharacters));
-            if (curScore < scoreToBeat) {
-                scoreToBeat = curScore;
-                output = curDate;
+            currentDate = makeDateFromStringAndFormat(string, formats[i]);
+            formattedInputParts = formatMoment(new Moment(currentDate), formats[i]).match(parseMultipleFormatChunker);
+            currentScore = compareArrays(inputParts, formattedInputParts);
+            if (currentScore < scoreToBeat) {
+                scoreToBeat = currentScore;
+                output = currentDate;
             }
         }
         return output;