// are provided, it will load the language file module. As a convenience,
// this function also returns the language values.
function loadLang(key, values) {
- var i,
+ var i, m,
parse = [];
if (!values && hasModule) {
}
for (i = 0; i < 12; i++) {
- parse[i] = new RegExp('^' + values.months[i] + '|^' + values.monthsShort[i].replace('.', ''), 'i');
+ m = moment([2000, i]);
+ parse[i] = new RegExp('^' + (values.months[i] || values.months(m, '')) +
+ '|^' + (values.monthsShort[i] || values.monthsShort(m, '')).replace('.', ''), 'i');
}
values.monthsParse = values.monthsParse || parse;
}
};
+ // returns language data
+ moment.langData = getLangDefinition;
+
+ // compare moment object
+ moment.isMoment = function (obj) {
+ return obj instanceof Moment;
+ };
+
+ // for typechecking Duration objects
+ moment.isDuration = function (obj) {
+ return obj instanceof Duration;
+ };
+
// Set default language, other languages will inherit from English.
moment.lang('en', {
months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
}
});
- // returns language data
- moment.langData = getLangDefinition;
-
- // compare moment object
- moment.isMoment = function (obj) {
- return obj instanceof Moment;
- };
-
- // for typechecking Duration objects
- moment.isDuration = function (obj) {
- return obj instanceof Duration;
- };
-
/************************************
Moment Prototype
test.equal(a.from(b), 'hace un día', 'preserve language of first moment');
test.equal(b.from(a), 'in a day', 'do not preserve language of second moment');
+ test.done();
+ },
+
+ "month name callback function" : function(test) {
+ test.expect(3);
+
+ function fakeReplace(m, format) {
+ if (/test/.test(format)) {
+ return "test";
+ }
+ if (m.date() === 1) {
+ return "date";
+ }
+ return 'default';
+ }
+
+ moment.lang('made-up', {
+ months : fakeReplace,
+ monthsShort : fakeReplace,
+ weekdays : fakeReplace,
+ weekdaysShort : fakeReplace,
+ weekdaysMin : fakeReplace
+ });
+
+ test.equal(moment().format('[test] dd ddd dddd MMM MMMM'), 'test test test test test test', 'format month name function should be able to access the format string');
+ test.equal(moment([2011, 0, 1]).format('dd ddd dddd MMM MMMM'), 'date date date date date', 'format month name function should be able to access the moment object');
+ test.equal(moment([2011, 0, 2]).format('dd ddd dddd MMM MMMM'), 'default default default default default', 'format month name function should be able to access the moment object');
+
test.done();
}
};