function getLangDefinition(m) {
var langKey = (typeof m === 'string') && m ||
m && m._lang ||
- currentLanguage;
+ null;
- return languages[langKey] || loadLang(langKey);
+ return langKey ? (languages[langKey] || loadLang(langKey)) : moment;
}
for (i = 0; i < langConfigProperties.length; i++) {
moment[langConfigProperties[i]] = languages[key][langConfigProperties[i]];
}
+ moment.monthsParse = languages[key].monthsParse;
currentLanguage = key;
}
};
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();
+ },
+
+ // the following tests should be removed after the 2.0.0 release as they will be deprecated
+ "lang accessors on the global object should exist < 2.0.0" : function(test) {
+ moment.lang('en');
+
+ var a = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|');
+ var i;
+
+ test.expect(a.length);
+
+ for (i = 0; i < a.length; i++) {
+ test.ok(moment[a[i]], "moment." + a[i] + " should exist");
+ }
+
+ test.done();
+ },
+
+ // the following tests should be removed after the 2.0.0 release as they will be deprecated
+ "lang accessors on the global object should change < 2.0.0" : function(test) {
+ moment.lang('en');
+
+ var a = 'months|monthsShort|weekdays|weekdaysShort|weekdaysMin|longDateFormat|calendar|relativeTime|ordinal'.split('|');
+ var i;
+ var en = {};
+
+ test.expect(a.length);
+
+ for (i = 0; i < a.length; i++) {
+ en[a[i]] = moment[a[i]];
+ }
+
+ moment.lang('fr');
+
+ for (i = 0; i < a.length; i++) {
+ test.notDeepEqual(en[a[i]], moment[a[i]], "the " + a[i] + " lang data should change on the global object");
+ }
+
+ test.done();
+ },
+
+ "manip lang accessors on the global object < 2.0.0" : function(test) {
+ test.expect(1);
+ moment.lang('en');
+
+ moment.months = ["test"];
+ test.equal(moment([2011, 0]).format('MMMM'), "test", "Should be able to manipulate the objects on the global object");
+
+ moment.lang('en');
+
test.done();
}
};