return date;
}
+ // Determines which language definition to use and returns it.
+ //
+ // With no parameters, it will return the global language. If you
+ // pass in a language key, such as 'en', it will return the
+ // definition for 'en', so long as 'en' has already been loaded using
+ // moment.lang. If you pass in a moment or duration instance, it
+ // will decide the language based on that, or default to the global
+ // language.
+ function getLangDefinition(m) {
+ var langKey = (typeof m === 'object') && m._lang ||
+ (typeof m === 'string') && m ||
+ currentLanguage;
+
+ return languages[langKey];
+ }
+
/************************************
Formatting
return formatFunctions[format];
}
- // Determines which language definition to use based on a moment instance.
- // If a moment has the _lang property set on it, it will return that
- // language; otherwise, it will return the global currentLanguage.
- function getLangDefinition(m) {
- return languages[(m && m._lang) || currentLanguage];
- }
-
// format date using native date object
function formatMoment(m, format) {
var lang = getLangDefinition(m);
}
});
+ // returns language data
+ moment.langData = getLangDefinition;
+
// compare moment object
moment.isMoment = function (obj) {
return obj instanceof Moment;
test.done();
},
+ "library langData" : function(test) {
+ test.expect(3);
+
+ // load Spanish
+ moment.lang('es');
+ // load Chinese
+ moment.lang('zh-cn');
+ // set global language
+ moment.lang('en');
+
+ test.equal(moment.langData().months[0], 'January', 'no arguments returns global');
+ test.equal(moment.langData('zh-cn').months[0], '一月', 'a string returns the language based on key');
+ test.equal(moment.langData(moment().lang('es')).months[0], 'Enero', "if you pass in a moment it uses the moment's language");
+
+ test.done();
+ },
+
"instance lang method" : function(test) {
test.expect(3);