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()