From: Iskren Ivov Chernev Date: Mon, 27 Apr 2020 17:40:18 +0000 (+0300) Subject: [bugfix] Set name when updating non-existent locale (#5470) X-Git-Tag: 2.25.0~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1021c019839cd3ac0abd04a7076fa513fa03567c;p=thirdparty%2Fmoment.git [bugfix] Set name when updating non-existent locale (#5470) Fixes #5043 --- diff --git a/src/lib/locale/locales.js b/src/lib/locale/locales.js index 438e6ba3d..9886aa96b 100644 --- a/src/lib/locale/locales.js +++ b/src/lib/locale/locales.js @@ -188,6 +188,12 @@ export function updateLocale(name, config) { parentConfig = tmpLocale._config; } config = mergeConfigs(parentConfig, config); + if (tmpLocale == null) { + // updateLocale is called for creating a new locale + // Set abbr so it will have a name (getters return + // undefined otherwise). + config.abbr = name; + } locale = new Locale(config); locale.parentLocale = locales[name]; locales[name] = locale; diff --git a/src/test/moment/locale_update.js b/src/test/moment/locale_update.js index 9352628e9..d8d1f76a4 100644 --- a/src/test/moment/locale_update.js +++ b/src/test/moment/locale_update.js @@ -286,6 +286,14 @@ test('update existing locale', function (assert) { moment.updateLocale('de', null); }); +test('update non-existing locale', function (assert) { + moment.locale('en'); + moment.updateLocale('dude', { months: ['Movember'] }); + assert.equal(moment.locale(), 'dude'); + assert.equal(moment().locale('dude').locale(), 'dude'); + moment.defineLocale('dude', null); +}); + test('reset locale', function (assert) { moment.locale('de'); var resultBeforeUpdate = moment('2017-02-01').format('YYYY MMM MMMM');