From f7b6ec88a81da3db2b8c81d8e22f93bcf83e5d1c Mon Sep 17 00:00:00 2001 From: iamkun Date: Tue, 7 May 2019 12:56:45 +0800 Subject: [PATCH] fix: Fix QuarterOfYear plugin bug --- src/plugin/quarterOfYear/index.js | 2 +- test/plugin/quarterOfYear.test.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/plugin/quarterOfYear/index.js b/src/plugin/quarterOfYear/index.js index 0ec48906b..681d7346b 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((this.month() % 3) + ((quarter - 1) * 3)) } return Math.ceil((this.month() + 1) / 3) } diff --git a/test/plugin/quarterOfYear.test.js b/test/plugin/quarterOfYear.test.js index 9b7152531..00d1b7cc6 100644 --- a/test/plugin/quarterOfYear.test.js +++ b/test/plugin/quarterOfYear.test.js @@ -31,6 +31,9 @@ it('set QuarterOfYear', () => { const d2 = '2013-02-05T05:06:07.000' expect(dayjs(d2).quarter(2).format()) .toBe(moment(d2).quarter(2).format()) + const d3 = '2018-11-25T05:06:07.000' + expect(dayjs(d3).quarter(3).format()) + .toBe(moment(d3).quarter(3).format()) }) it('add subtract quarter', () => {