return;
}
- moment[field] = function (format) {
- var i, m, str,
- method = moment.fn._lang[field] || Language.prototype[field],
- results = [];
-
- for (i = 0; i < count; i++) {
- m = moment().utc().set(setter, i);
- str = method.call(moment.fn._lang, m, format || '');
- results.push(str);
+ moment[field] = function (format, index) {
+ var i,
+ method = moment.fn._lang[field],
+ results = [],
+ getter = function (i) {
+ var m = moment().utc().set(setter, i);
+ return method.call(moment.fn._lang, m, format || '');
+ };
+
+ index = (typeof format === 'number') ? format : index;
+
+ if (index) {
+ return getter(index);
+ }
+ else {
+ for (i = 0; i < count; i++) {
+ results.push(getter(i));
+ }
+ return results;
}
-
- return results;
};
}
test.done();
},
+ "index" : function (test) {
+ test.expect(5);
+ test.equal(moment.months(2), "March");
+ test.equal(moment.monthsShort(2), "Mar");
+ test.equal(moment.weekdays(2), "Tuesday");
+ test.equal(moment.weekdaysShort(2), "Tue");
+ test.equal(moment.weekdaysMin(2), "Tu");
+ test.done();
+ },
+
"localized" : function (test) {
var months = "one_two_three_four_five_six_seven_eight_nine_ten_eleven_twelve".split('_'),
monthsShort = "on_tw_th_fo_fi_si_se_ei_ni_te_el_tw".split("_"),
weekdaysMin: weekdaysMin
});
- test.expect(5);
+ test.expect(10);
test.deepEqual(moment.months(), months);
test.deepEqual(moment.monthsShort(), monthsShort);
test.deepEqual(moment.weekdays(), weekdays);
test.deepEqual(moment.weekdaysShort(), weekdaysShort);
test.deepEqual(moment.weekdaysMin(), weekdaysMin);
+
+ test.equal(moment.months(2), "three");
+ test.equal(moment.monthsShort(2), "th");
+ test.equal(moment.weekdays(2), "three");
+ test.equal(moment.weekdaysShort(2), "th");
+ test.equal(moment.weekdaysMin(2), "3");
+
test.done();
},
}
});
- test.expect(3);
+ test.expect(5);
test.deepEqual(moment.monthsShort(), monthsShort);
test.deepEqual(moment.monthsShort('MMM'), monthsShort);
test.deepEqual(moment.monthsShort('-MMM-'), monthsShortWeird);
+
+ test.deepEqual(moment.monthsShort('MMM', 2), 'three');
+ test.deepEqual(moment.monthsShort('-MMM-', 2), 'threesy');
+
test.done();
}
};