Skip to content

Commit

Permalink
fix: update localeData plugin to support meridiem
Browse files Browse the repository at this point in the history
fix #1172
  • Loading branch information
iamkun committed Oct 28, 2020
1 parent 990012b commit 043c3b7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/plugin/localeData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand All @@ -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
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/plugin/localeData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
2 changes: 2 additions & 0 deletions types/plugin/localeData.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 043c3b7

Please sign in to comment.