Skip to content

Commit

Permalink
fix: fix weekYear plugin missing locale bug
Browse files Browse the repository at this point in the history
fix #1304
  • Loading branch information
iamkun committed Jan 6, 2021
1 parent cc993f0 commit 6348df5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/locale/en-gb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// English (United Kingdom) [en-gb]
import dayjs from 'dayjs'
import dayjs from '../index'

const locale = {
name: 'en-gb',
Expand Down
3 changes: 3 additions & 0 deletions src/plugin/weekYear/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default (o, c) => {
if (weekOfYear === 1 && month === 11) {
return year + 1
}
if (month === 0 && weekOfYear >= 52) {
return year - 1
}
return year
}
}
23 changes: 21 additions & 2 deletions test/plugin/weekYear.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MockDate from 'mockdate'
import dayjs from '../../src'
import weekYear from '../../src/plugin/weekYear'
import weekOfYear from '../../src/plugin/weekOfYear'
import '../../src/locale/en-gb'

dayjs.extend(weekYear)
dayjs.extend(weekOfYear)
Expand All @@ -24,7 +25,25 @@ it('Week Year', () => {
]
daySet.forEach((d) => {
const [day, result] = d
expect(dayjs(day).weekYear()).toBe(result)
expect(dayjs(day).weekYear()).toBe(moment(day).weekYear())
const dResult = dayjs(day).weekYear()
expect(dResult).toBe(result)
expect(dResult).toBe(moment(day).weekYear())
})
})

it('yearStart: 4', () => {
const daySet = [
['2020-12-31', 2020],
['2021-01-01', 2020],
['2021-01-02', 2020],
['2021-01-03', 2020],
['2021-01-04', 2021],
['2021-01-05', 2021]
]
daySet.forEach((d) => {
const [day, result] = d
const dResult = dayjs(day).locale('en-gb').weekYear()
expect(dResult).toBe(result)
expect(dResult).toBe(moment(day).locale('en-gb').weekYear())
})
})

0 comments on commit 6348df5

Please sign in to comment.