Skip to content

Commit

Permalink
chore: Update AdvancedFormat plugin parse gggg for week year
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Mar 10, 2019
1 parent a892608 commit 0fc2397
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/plugin/advancedFormat/index.js
Expand Up @@ -13,12 +13,14 @@ export default (o, c, d) => { // locale needed later
const locale = this.$locale()
const utils = this.$utils()
const str = formatStr || FORMAT_DEFAULT
const result = str.replace(/Q|wo|Do|X|x|k{1,2}|S/g, (match) => {
const result = str.replace(/Q|wo|gggg|Do|X|x|k{1,2}|S/g, (match) => {
switch (match) {
case 'Q':
return Math.ceil((this.$M + 1) / 3)
case 'Do':
return locale.ordinal(this.$D)
case 'gggg':
return this.weekYear()
case 'wo':
return locale.ordinal(this.week(), 'W') // W for week
case 'k':
Expand Down
7 changes: 7 additions & 0 deletions test/plugin/advancedFormat.test.js
Expand Up @@ -3,8 +3,10 @@ import moment from 'moment'
import dayjs from '../../src'
import advancedFormat from '../../src/plugin/advancedFormat'
import weekOfYear from '../../src/plugin/weekOfYear'
import weekYear from '../../src/plugin/weekYear'
import '../../src/locale/zh-cn'

dayjs.extend(weekYear)
dayjs.extend(weekOfYear)
dayjs.extend(advancedFormat)

Expand Down Expand Up @@ -75,3 +77,8 @@ it('Format Week of Year wo', () => {
expect(dayjs(d).locale('zh-cn').format('wo'))
.toBe(moment(d).locale('zh-cn').format('wo'))
})

it('Format Week Year gggg', () => {
const d = '2018-12-31'
expect(dayjs(d).format('gggg')).toBe(moment(d).format('gggg'))
})

0 comments on commit 0fc2397

Please sign in to comment.