diff --git a/src/plugin/weekOfYear/index.js b/src/plugin/weekOfYear/index.js index 9c7ae6951..7251d5af4 100644 --- a/src/plugin/weekOfYear/index.js +++ b/src/plugin/weekOfYear/index.js @@ -6,25 +6,14 @@ export default (o, c, d) => { if (week !== null) { return this.add((week - this.week()) * 7, 'day') } - const weekStart = this.$locale().weekStart || 0 - - // d(this) clone is for badMutable plugin - const endOfYear = d(this).endOf(Y) - if ( - weekStart === 0 && - endOfYear.day() !== 6 && - this.month() === 11 && - 31 - this.date() <= endOfYear.day() - ) { - return 1 - } - const startOfYear = d(this).startOf(Y) const compareDay = startOfYear.subtract(startOfYear.day() - weekStart, D).subtract(1, MS) const diffInWeek = this.diff(compareDay, W, true) - return Math.ceil(diffInWeek) + const result = Math.ceil(diffInWeek) + return result > 52 ? 1 : result } + proto.weeks = function (week = null) { return this.week(week) } diff --git a/test/plugin/weekOfYear.test.js b/test/plugin/weekOfYear.test.js index a0c446a86..980b4bc77 100644 --- a/test/plugin/weekOfYear.test.js +++ b/test/plugin/weekOfYear.test.js @@ -40,6 +40,7 @@ it('Week of year with locale', () => { // Edges expect(dayjs('2018-12-30').week()).toBe(moment('2018-12-30').week()) expect(dayjs('2019-12-29').week()).toBe(moment('2019-12-29').week()) + expect(dayjs('2019-12-30').week()).toBe(moment('2019-12-30').week()) }) it('Format w ww wo', () => {