Skip to content

Commit

Permalink
fix: Fix .locale() handel unsupported locale
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Dec 18, 2019
1 parent 6d51435 commit 78ec173
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 9 additions & 0 deletions test/locale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 78ec173

Please sign in to comment.