Skip to content

Commit 78ec173

Browse files
committedDec 18, 2019
fix: Fix .locale() handel unsupported locale
1 parent 6d51435 commit 78ec173

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed
 

‎src/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ class Dayjs {
366366
locale(preset, object) {
367367
if (!preset) return this.$L
368368
const that = this.clone()
369-
that.$L = parseLocale(preset, object, true)
369+
const nextLocaleName = parseLocale(preset, object, true)
370+
if (nextLocaleName) that.$L = nextLocaleName
370371
return that
371372
}
372373

‎test/locale.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,12 @@ describe('Instance locale inheritance', () => {
121121
expect(dayjs.locale()).toBe(moment.locale())
122122
})
123123
})
124+
125+
126+
it('Not supported locale string fallback to previous one', () => {
127+
const D = dayjs()
128+
const DFormat = D.format()
129+
const D2 = D.locale('not_supported_locale_string')
130+
const D2Format = D2.format()
131+
expect(DFormat).toBe(D2Format)
132+
})

0 commit comments

Comments
 (0)
Please sign in to comment.