moment[field] = function (format, index) {
var i, getter,
- method = moment.fn._locale[field],
+ method = moment._locale[field],
results = [];
if (typeof format === 'number') {
getter = function (i) {
var m = moment().utc().set(setter, i);
- return method.call(moment.fn._locale, m, format || '');
+ return method.call(moment._locale, m, format || '');
};
if (index != null) {
}
function loadLocale(name) {
+ var oldLocale = null;
if (!locales[name] && hasModule) {
try {
+ oldLocale = moment.locale();
require('./locale/' + name);
+ // because defineLocale currently also sets the global locale, we want to undo that for lazy loaded locales
+ moment.locale(oldLocale);
} catch (e) { }
}
return locales[name];
}
if (data) {
- moment.duration.fn._locale = moment.fn._locale = data;
+ moment.duration._locale = moment._locale = data;
}
}
- return moment.fn._locale._abbr;
+ return moment._locale._abbr;
};
moment.defineLocale = function (name, values) {
locales[name] = new Locale();
}
locales[name].set(values);
+
+ // backwards compat for now: also set the locale
+ moment.locale(name);
+
return locales[name];
} else {
+ // useful for testing
delete locales[name];
return null;
}
}
if (!key) {
- return moment.fn._locale;
+ return moment._locale;
}
if (!isArray(key)) {
grunt.file.write(config.dest, modifiedContents);
});
+ var languageReset = 'moment.locale(\'en\');'
+
function determineEmbeddedContent(files) {
var embeddedContent = '';
files.forEach(function (file) {
embeddedContent += transformFile(file);
});
+ embeddedContent += '\n ' + languageReset + '\n';
return embeddedContent;
}
"defineLocale" : function (test) {
moment.locale("en");
moment.defineLocale("dude", {months: ["Movember"]});
- test.equal(moment().locale(), "en", "defineLocale doesn't set it");
+ test.equal(moment().locale(), "dude", "defineLocale also sets it");
test.equal(moment().locale("dude").locale(), "dude", "defineLocale defines a locale");
test.done();
},
test.equal(registered, 'return-this', 'returns the locale configured');
+ test.done();
+ },
+
+ "changing the global locale doesn't affect existing instances" : function (test) {
+ moment.locale('en');
+ var mom = moment();
+ moment.locale('pr');
+ test.equal('en', moment.locale());
test.done();
}
};