// instance. Otherwise, it will return the locale configuration
// variables for this instance.
locale : function (key) {
+ var newLocaleData;
+
if (key === undefined) {
return this._locale._abbr;
} else {
- this._locale = moment.localeData(key);
+ newLocaleData = moment.localeData(key);
+ if (newLocaleData != null) {
+ this._locale = newLocaleData;
+ }
return this;
}
},
if (key === undefined) {
return this.localeData();
} else {
- this._locale = moment.localeData(key);
- return this;
+ return this.locale(key);
}
}
),
test.equal(m.locale(), 'fr', 'instance locale reset to global locale');
test.done();
+ },
+
+ 'moment().locale with missing key doesn\'t change locale' : function (test) {
+ test.equal(moment().locale('boo').localeData(), moment.localeData(),
+ 'preserve global locale in case of bad locale id');
+ test.done();
+ },
+
+ 'moment().lang with missing key doesn\'t change locale' : function (test) {
+ test.equal(moment().lang('boo').localeData(), moment.localeData(),
+ 'preserve global locale in case of bad locale id');
+ test.done();
}
};