From 043c3b7aa733853479c0c39081a9788aa4ed0410 Mon Sep 17 00:00:00 2001 From: iamkun Date: Wed, 28 Oct 2020 13:53:53 +0800 Subject: [PATCH] fix: update localeData plugin to support meridiem fix #1172 --- src/plugin/localeData/index.js | 7 ++++--- test/plugin/localeData.test.js | 7 +++++++ types/plugin/localeData.d.ts | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugin/localeData/index.js b/src/plugin/localeData/index.js index 65d6e234b..579c0ec36 100644 --- a/src/plugin/localeData/index.js +++ b/src/plugin/localeData/index.js @@ -28,8 +28,8 @@ export default (o, c, dayjs) => { // locale needed later (instance ? instance.format('dd') : getShort(this, 'weekdaysMin', 'weekdays', 2)), weekdaysShort: instance => (instance ? instance.format('ddd') : getShort(this, 'weekdaysShort', 'weekdays', 3)), - longDateFormat: format => getLongDateFormat(this.$locale(), format) - + longDateFormat: format => getLongDateFormat(this.$locale(), format), + meridiem: this.$locale().meridiem } } proto.localeData = function () { @@ -45,7 +45,8 @@ export default (o, c, dayjs) => { // locale needed later weekdaysMin: () => dayjs.weekdaysMin(), months: () => dayjs.months(), monthsShort: () => dayjs.monthsShort(), - longDateFormat: format => getLongDateFormat(localeObject, format) + longDateFormat: format => getLongDateFormat(localeObject, format), + meridiem: localeObject.meridiem } } diff --git a/test/plugin/localeData.test.js b/test/plugin/localeData.test.js index 829856406..6aa9637b6 100644 --- a/test/plugin/localeData.test.js +++ b/test/plugin/localeData.test.js @@ -103,3 +103,10 @@ it('Locale order', () => { moment.locale('en') expect(dayjs.weekdays(true)).toEqual(moment.weekdays(true)) }) + +it('meridiem', () => { + dayjs.locale('zh-cn') + expect(typeof dayjs.localeData().meridiem).toEqual('function') + expect(typeof dayjs().localeData().meridiem).toEqual('function') + dayjs.locale('en') +}) diff --git a/types/plugin/localeData.d.ts b/types/plugin/localeData.d.ts index 6b0c11c02..bc0aa14bd 100644 --- a/types/plugin/localeData.d.ts +++ b/types/plugin/localeData.d.ts @@ -15,6 +15,7 @@ declare module 'dayjs' { months(instance?: Dayjs): MonthNames; monthsShort(instance?: Dayjs): MonthNames; longDateFormat(format: string): string; + meridiem(hour?: number, minute?: number, isLower?: boolean): string; } interface GlobalLocaleDataReturn { @@ -25,6 +26,7 @@ declare module 'dayjs' { months(): MonthNames; monthsShort(): MonthNames; longDateFormat(format: string): string; + meridiem(hour?: number, minute?: number, isLower?: boolean): string; } interface Dayjs {