Skip to content

Commit

Permalink
fix: Fix QuarterOfYear plugin bug (#591)
Browse files Browse the repository at this point in the history
  • Loading branch information
1 parent b3df1ee commit 3ce1eab
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugin/quarterOfYear/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 3 additions & 0 deletions test/plugin/quarterOfYear.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit 3ce1eab

Please sign in to comment.