diff --git a/src/plugin/localeData/index.js b/src/plugin/localeData/index.js index c8008a22..329090d2 100644 --- a/src/plugin/localeData/index.js +++ b/src/plugin/localeData/index.js @@ -17,7 +17,8 @@ export default (o, c, dayjs) => { // locale needed later weekdaysMin: instance => (instance ? instance.format('dd') : getShort(this, 'weekdaysMin', 'weekdays', 2)), weekdaysShort: instance => - (instance ? instance.format('ddd') : getShort(this, 'weekdaysShort', 'weekdays', 3)) + (instance ? instance.format('ddd') : getShort(this, 'weekdaysShort', 'weekdays', 3)), + longDateFormat: format => this.$locale().formats[format] } } proto.localeData = function () { diff --git a/test/plugin/localeData.test.js b/test/plugin/localeData.test.js index 151713b6..28983287 100644 --- a/test/plugin/localeData.test.js +++ b/test/plugin/localeData.test.js @@ -2,8 +2,10 @@ import MockDate from 'mockdate' import moment from 'moment' import dayjs from '../../src' import localeData from '../../src/plugin/localeData' +import localizedFormat from '../../src/plugin/localizedFormat' import '../../src/locale/zh-cn' +dayjs.extend(localizedFormat) dayjs.extend(localeData) beforeEach(() => { @@ -14,7 +16,7 @@ afterEach(() => { MockDate.reset() }) -it('instance localeData', () => { +it('Instance localeData', () => { const d = dayjs() const m = moment() const dayjsLocaleData = dayjs().localeData() @@ -28,9 +30,14 @@ it('instance localeData', () => { expect(dayjsLocaleData.weekdaysMin()).toEqual(momentLocaleData.weekdaysMin()) expect(dayjsLocaleData.weekdaysShort(d)).toBe(momentLocaleData.weekdaysShort(m)) expect(dayjsLocaleData.weekdaysShort()).toEqual(momentLocaleData.weekdaysShort()) + const longDateFormats = ['LT', 'LTS', 'L', 'LL', 'LLL', 'LLLL'] + longDateFormats.forEach((f) => { + expect(dayjsLocaleData.longDateFormat(f)).toEqual(momentLocaleData.longDateFormat(f)) + }) }) -it('global localeData', () => { + +it('Global localeData', () => { dayjs.locale('zh-cn') moment.locale('zh-cn') let dayjsLocaleData = dayjs.localeData()