Skip to content

Commit

Permalink
fix: fix locally using region tag changing global locale (iamkun#1875)
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanc1to committed May 31, 2022
1 parent 05cba7e commit 7af7c23
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const parseLocale = (preset, object, isLocal) => {
}
const presetSplit = preset.split('-')
if (!l && presetSplit.length > 1) {
return parseLocale(presetSplit[0])
return parseLocale(presetSplit[0], object, isLocal)
}
} else {
const { name } = preset
Expand Down
22 changes: 22 additions & 0 deletions test/locale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ it('set locale for one instance only', () => {
.toBe('Saturday 28, April')
})

// The following two tests were added in response to this bug:
// <https://github.com/iamkun/dayjs/issues/1875>.
it('handles region tags', () => {
expect(dayjs('2018-4-28')
.locale('es-us').format(format))
.toBe('sábado 28, abril')

expect(dayjs('2018-4-28')
.format(format))
.toBe('Saturday 28, April')
})

it('handles unknown region tags with the base language', () => {
expect(dayjs('2018-4-28')
.locale('es-XX').format(format))
.toBe('sábado 28, abril')

expect(dayjs('2018-4-28')
.format(format))
.toBe('Saturday 28, April')
})

it('set global locale', () => {
dayjs.locale('en')
expect(dayjs('2018-4-28').format(format))
Expand Down

0 comments on commit 7af7c23

Please sign in to comment.