i,
currentScore;
- for (i = config._f.length; i > 0; i--) {
+ for (i = 0; i < config._f.length; i++) {
tempConfig = extend({}, config);
- tempConfig._f = config._f[i - 1];
+ tempConfig._f = config._f[i];
makeDateFromStringAndFormat(tempConfig);
tempMoment = new Moment(tempConfig);
- if (tempMoment.isValid()) {
- bestMoment = tempMoment;
- break;
- }
-
currentScore = compareArrays(tempConfig._a, tempMoment.toArray());
if (currentScore < scoreToBeat) {
},
"string with array of formats" : function(test) {
- test.expect(3);
- test.equal(moment('11-02-1999', ['MM-DD-YYYY', 'DD-MM-YYYY']).format('MM DD YYYY'), '02 11 1999', 'switching month and day');
+ test.expect(6);
+
+ 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('1999-02-11', ['MM/DD/YYYY', 'YYYY-MM-DD', 'MM-DD-YYYY']).format('MM DD YYYY'), '02 11 1999', 'year first');
+
+ test.equal(moment('02-11-1999', ['MM/DD/YYYY', 'YYYY-MM-DD']).format('MM DD YYYY'), '02 11 1999', 'year last');
+ test.equal(moment('1999-02-11', ['MM/DD/YYYY', 'YYYY-MM-DD']).format('MM DD YYYY'), '02 11 1999', 'year first');
+
+ test.equal(moment('01', ["MM", "DD"])._f, "MM", "Should use first valid format");
+
test.done();
},
"format multiple with zone" : function(test) {
test.expect(1);
- var b = moment('2012-10-08 -1200', ['YYYY ZZ', 'YYYY-MM-DD ZZ']);
+ var b = moment('2012-10-08 -1200', ['YYYY-MM-DD HH:mm ZZ', 'YYYY-MM-DD ZZ', 'YYYY-MM-DD']);
test.equals(b.format('YYYY-MM'), '2012-10', 'Parsing multiple formats should not crash with different sized formats');
test.done();
},