]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Set name when updating non-existent locale (#5470)
authorIskren Ivov Chernev <iskren.chernev@gmail.com>
Mon, 27 Apr 2020 17:40:18 +0000 (20:40 +0300)
committerGitHub <noreply@github.com>
Mon, 27 Apr 2020 17:40:18 +0000 (20:40 +0300)
Fixes #5043

src/lib/locale/locales.js
src/test/moment/locale_update.js

index 438e6ba3dbb301516aeebc24db5dcf9ad0b417f5..9886aa96b943a261193540d8632d0180e4ec4e9f 100644 (file)
@@ -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;
index 9352628e9d397cd3d61360a873ac7866c745ebc3..d8d1f76a45430e3a881717a2336d00797919c0f9 100644 (file)
@@ -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');