Skip to content

Commit

Permalink
fix: Fix DayOfYear plugin when using BadMutable plugin (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanyeh authored Jun 1, 2021
1 parent 06f88f4 commit 0b0c6a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/plugin/dayOfYear/index.js
Original file line number Diff line number Diff line change
@@ -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')
}
}
11 changes: 10 additions & 1 deletion test/plugin/badMutable.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0b0c6a3

Please sign in to comment.