Skip to content

Commit

Permalink
Merge pull request #4242 from cmyers:develop
Browse files Browse the repository at this point in the history
[bugfix] updateLocale now tries to load parent, fixes #3626
  • Loading branch information
ichernev committed Nov 11, 2017
2 parents 6beb383 + 695fd75 commit d26f97e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/locale/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ export function defineLocale (name, config) {

export function updateLocale(name, config) {
if (config != null) {
var locale, parentConfig = baseConfig;
var locale, tmpLocale, parentConfig = baseConfig;
// MERGE
if (locales[name] != null) {
parentConfig = locales[name]._config;
tmpLocale = loadLocale(name);
if (tmpLocale != null) {
parentConfig = tmpLocale._config;
}
config = mergeConfigs(parentConfig, config);
locale = new Locale(config);
Expand Down
8 changes: 8 additions & 0 deletions src/test/moment/locale_update.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,11 @@ test('months', function (assert) {
});
assert.ok(moment.utc('2015-01-01', 'YYYY-MM-DD').format('MMMM'), 'First', 'months uses child');
});

test('update existing locale', function (assert) {
moment.updateLocale('de', {
monthsShort: ['JAN', 'FEB', 'MÄR', 'APR', 'MAI', 'JUN', 'JUL', 'AUG', 'SEP', 'OKT', 'NOV', 'DEZ']
});
assert.equal(moment('2017-02-01').format('YYYY MMM MMMM'), '2017 FEB Februar');
moment.updateLocale('de', null);
});

0 comments on commit d26f97e

Please sign in to comment.