Skip to content

Commit

Permalink
fix: fix weekYear plugin missing locale bug (#1319)
Browse files Browse the repository at this point in the history
* fix: fix weekYear plugin missing locale bug

fix #1304
  • Loading branch information
iamkun authored Jan 6, 2021
1 parent cc993f0 commit 344bdc0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
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 344bdc0

Please sign in to comment.