diff --git a/src/plugin/quarterOfYear/index.js b/src/plugin/quarterOfYear/index.js index 0ec48906b..b9f538232 100644 --- a/src/plugin/quarterOfYear/index.js +++ b/src/plugin/quarterOfYear/index.js @@ -4,7 +4,7 @@ export default (o, c) => { const proto = c.prototype proto.quarter = function (quarter) { if (!this.$utils().u(quarter)) { - return this.add((quarter - 1) * 3, M) + return this.month(((quarter - 1) * 3) + (this.month() % 3), M) } return Math.ceil((this.month() + 1) / 3) } diff --git a/test/plugin/quarterOfYear.test.js b/test/plugin/quarterOfYear.test.js index 9b7152531..f0cc7c83f 100644 --- a/test/plugin/quarterOfYear.test.js +++ b/test/plugin/quarterOfYear.test.js @@ -33,6 +33,22 @@ it('set QuarterOfYear', () => { .toBe(moment(d2).quarter(2).format()) }) +it('set 3rd QuarterOfYear', () => { + const d1 = '2018-11-25' + expect(dayjs(d1) + .quarter(3) + .format()).toBe(moment(d1) + .quarter(3) + .format()) + + const d2 = '2018-03-09' + expect(dayjs(d2) + .quarter(3) + .format()).toBe(moment(d2) + .quarter(3) + .format()) +}) + it('add subtract quarter', () => { expect(dayjs().add(2, 'quarter').format()) .toBe(moment().add(2, 'quarter').format())