diff --git a/src/index.js b/src/index.js index 19c409078..d9675efe3 100644 --- a/src/index.js +++ b/src/index.js @@ -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 diff --git a/test/locale.test.js b/test/locale.test.js index 0e6fd06eb..d44d4cbc1 100644 --- a/test/locale.test.js +++ b/test/locale.test.js @@ -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: +// . +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))