addTimeToArrayFromToken(tokens[i], parsedInput, config);
}
}
+
+ // add remaining unparsed input to the string
+ if (string) {
+ config._il = string;
+ }
+
// handle am pm
if (config._isPm && config._a[3] < 12) {
config._a[3] += 12;
currentScore = compareArrays(tempConfig._a, tempMoment.toArray());
+ // if there is any input that was not parsed
+ // add a penalty for that format
+ if (tempMoment._il) {
+ currentScore += tempMoment._il.length;
+ }
+
if (currentScore < scoreToBeat) {
scoreToBeat = currentScore;
bestMoment = tempMoment;
},
"string with array of formats" : function(test) {
- test.expect(10);
+ test.expect(12);
test.equal(moment('11-02-1999', ['MM-DD-YYYY', 'DD-MM-YYYY']).format('MM DD YYYY'), '11 02 1999', 'switching month and day');
test.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year last');
test.equal(moment('13-14-1999', ['MM/DD/YYYY', 'DD/MM/YYYY']).format('MM DD YYYY'), '01 14 2000', 'either can be a month, month first format');
test.equal(moment('13-14-1999', ['DD/MM/YYYY', 'MM/DD/YYYY']).format('MM DD YYYY'), '02 13 2000', 'either can be a month, day first format');
+ test.equal(moment('13-14-98', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YY', 'use two digit year');
+ test.equal(moment('13-14-1998', ['DD MM YY', 'DD MM YYYY'])._f, 'DD MM YYYY', 'use four digit year');
+
test.equal(moment('01', ["MM", "DD"])._f, "MM", "Should use first valid format");
test.done();