Skip to content

Commit

Permalink
fix: Update LocaleData plugin to support dayjs().longDateFormat()
Browse files Browse the repository at this point in the history
fix #680
  • Loading branch information
iamkun committed Nov 15, 2019
1 parent 9ad2e47 commit 8cb274e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/plugin/localeData/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
11 changes: 9 additions & 2 deletions test/plugin/localeData.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -14,7 +16,7 @@ afterEach(() => {
MockDate.reset()
})

it('instance localeData', () => {
it('Instance localeData', () => {
const d = dayjs()
const m = moment()
const dayjsLocaleData = dayjs().localeData()
Expand All @@ -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()
Expand Down

0 comments on commit 8cb274e

Please sign in to comment.