From 48b42b808ffa77e81c8f85731d2ba5e0c5c5095d Mon Sep 17 00:00:00 2001 From: Sean Yeh <109418+seanyeh@users.noreply.github.com> Date: Sun, 30 May 2021 07:15:08 -0500 Subject: [PATCH] fix: Fix DayOfYear plugin when using BadMutable plugin --- src/plugin/dayOfYear/index.js | 5 +++-- test/plugin/badMutable.test.js | 11 ++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/plugin/dayOfYear/index.js b/src/plugin/dayOfYear/index.js index 018ef3396..f4960da6e 100644 --- a/src/plugin/dayOfYear/index.js +++ b/src/plugin/dayOfYear/index.js @@ -1,7 +1,8 @@ -export default (o, c) => { +export default (o, c, d) => { const proto = c.prototype proto.dayOfYear = function (input) { - const dayOfYear = Math.round((this.startOf('day') - this.startOf('year')) / 864e5) + 1 + // d(this) is for badMutable + const dayOfYear = Math.round((d(this).startOf('day') - d(this).startOf('year')) / 864e5) + 1 return input == null ? dayOfYear : this.add(input - dayOfYear, 'day') } } diff --git a/test/plugin/badMutable.test.js b/test/plugin/badMutable.test.js index bfd351520..b101af68c 100644 --- a/test/plugin/badMutable.test.js +++ b/test/plugin/badMutable.test.js @@ -2,10 +2,12 @@ import MockDate from 'mockdate' import moment from 'moment' import dayjs from '../../src' import badMutable from '../../src/plugin/badMutable' +import dayOfYear from '../../src/plugin/dayOfYear' import weekOfYear from '../../src/plugin/weekOfYear' import '../../src/locale/zh-cn' dayjs.extend(badMutable) +dayjs.extend(dayOfYear) dayjs.extend(weekOfYear) beforeEach(() => { @@ -188,7 +190,14 @@ it('isAfter isBefore isSame', () => { expect(d.isAfter()).toBe(false) }) -it('WeekOfYear get week won"t change instance', () => { +it('DayOfYear get day won\'t change instance', () => { + const d = dayjs() + const format = d.format() + d.dayOfYear() + expect(d.format()).toBe(format) +}) + +it('WeekOfYear get week won\'t change instance', () => { const d = dayjs() const format = d.format() d.week()