From: Tim Wood Date: Wed, 11 Apr 2012 03:13:03 +0000 (-0700) Subject: Fixing string+formats parsing with new iterative parser X-Git-Tag: 1.6.0~1^2~11^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=067bb40054054b43dceba0a5c3bba6d9bde0d559;p=thirdparty%2Fmoment.git Fixing string+formats parsing with new iterative parser --- diff --git a/moment.js b/moment.js index ec30728ed..cd489fc7a 100644 --- a/moment.js +++ b/moment.js @@ -432,18 +432,19 @@ // 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;