diff --git a/src/index.js b/src/index.js index 3c9fc987..9c4b93c1 100644 --- a/src/index.js +++ b/src/index.js @@ -366,7 +366,8 @@ class Dayjs { locale(preset, object) { if (!preset) return this.$L const that = this.clone() - that.$L = parseLocale(preset, object, true) + const nextLocaleName = parseLocale(preset, object, true) + if (nextLocaleName) that.$L = nextLocaleName return that } diff --git a/test/locale.test.js b/test/locale.test.js index 1ac0aa9c..48e1f566 100644 --- a/test/locale.test.js +++ b/test/locale.test.js @@ -121,3 +121,12 @@ describe('Instance locale inheritance', () => { expect(dayjs.locale()).toBe(moment.locale()) }) }) + + +it('Not supported locale string fallback to previous one', () => { + const D = dayjs() + const DFormat = D.format() + const D2 = D.locale('not_supported_locale_string') + const D2Format = D2.format() + expect(DFormat).toBe(D2Format) +})