Skip to content

Commit

Permalink
fix: Fix .add day/week decimal rouding bug
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkun committed Apr 8, 2019
1 parent 40bea40 commit 800f6c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class Dayjs {
const unit = Utils.p(units)
const instanceFactorySet = (n) => {
const date = new Date(this.$d)
date.setDate(date.getDate() + (n * number))
date.setDate(date.getDate() + Math.round(n * number))
return Utils.w(date, this)
}
if (unit === C.M) {
Expand Down
7 changes: 7 additions & 0 deletions test/manipulate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ it('Add Time days', () => {
expect(dayjs().add('2', 'years').valueOf()).toBe(moment().add('2', 'years').valueOf())
})

it('Add Time with decimal', () => {
expect(dayjs().add(0.4, 'day').valueOf()).toBe(moment().add(0.4, 'day').valueOf())
expect(dayjs().add(0.5, 'day').valueOf()).toBe(moment().add(0.5, 'day').valueOf())
expect(dayjs().add(0.4, 'week').valueOf()).toBe(moment().add(0.4, 'week').valueOf())
expect(dayjs().add(0.5, 'week').valueOf()).toBe(moment().add(0.5, 'week').valueOf())
})

it('Subtract Time days', () => {
expect(dayjs().subtract(1, 'days').valueOf()).toBe(moment().subtract(1, 'days').valueOf())
})

0 comments on commit 800f6c9

Please sign in to comment.