Skip to content

Commit 79b86db

Browse files
committed
fix: Fix WeekOfYear Plugin wrong calender week number bug
fix #760
1 parent 66ce23f commit 79b86db

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/plugin/weekOfYear/index.js

+3-14
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,14 @@ export default (o, c, d) => {
66
if (week !== null) {
77
return this.add((week - this.week()) * 7, 'day')
88
}
9-
109
const weekStart = this.$locale().weekStart || 0
11-
12-
// d(this) clone is for badMutable plugin
13-
const endOfYear = d(this).endOf(Y)
14-
if (
15-
weekStart === 0 &&
16-
endOfYear.day() !== 6 &&
17-
this.month() === 11 &&
18-
31 - this.date() <= endOfYear.day()
19-
) {
20-
return 1
21-
}
22-
2310
const startOfYear = d(this).startOf(Y)
2411
const compareDay = startOfYear.subtract(startOfYear.day() - weekStart, D).subtract(1, MS)
2512
const diffInWeek = this.diff(compareDay, W, true)
26-
return Math.ceil(diffInWeek)
13+
const result = Math.ceil(diffInWeek)
14+
return result > 52 ? 1 : result
2715
}
16+
2817
proto.weeks = function (week = null) {
2918
return this.week(week)
3019
}

test/plugin/weekOfYear.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ it('Week of year with locale', () => {
4040
// Edges
4141
expect(dayjs('2018-12-30').week()).toBe(moment('2018-12-30').week())
4242
expect(dayjs('2019-12-29').week()).toBe(moment('2019-12-29').week())
43+
expect(dayjs('2019-12-30').week()).toBe(moment('2019-12-30').week())
4344
})
4445

4546
it('Format w ww wo', () => {

0 commit comments

Comments
 (0)